I have a form like;
<form method="post" action="test.php">
<input type="text" name="field1" class="class1"><span class="info">
<input type="text" name="field2" class="class1"><span class="info">
<input type="text" name="field3" class="class1"><span class="info">
</form>
I want to update the corresponding info span when user finish typing or when cursor goes out of form field. keypress() function + setTimeout + clearTimeout will work in the case of typing, but fails in the case of Ctrl+V, or some other method, where keypress is not relevant. The input data is passed into an ajax request like;
$.ajax({
type: 'POST',
url: 'ajaxhandler.php',
data: 'item='+fieldvalue,//class1 values. field1 value, field2 value etc
cache: false,
success: function(result) {
if(result == "true"){
//update span with true
}else{
//update span with false
}
}
});
I am trying to achieve this. After user provide input to form field, it may pass to ajax and the corresponding info span may be updated with the ajax reply, either true or false. How can I do this?
you could use the change event like so
http://jsfiddle.net/kasperfish/Zxn3Q/1/
$('input[type=text]').on('change', function(){
var input=$(this);
//do your ajax call here
alert('this can be an ajax call');
input.next('span.info').html(input.val());
});
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With