The js function will not work in my SITE but when I try it in JSFIDDLE it shows to work fine. I have included DOM ready but it doesn’t trigger anything. I checked with firefox and input value is not posted at all. How can I get the JS function to fire up properly after user stops typing?
JS
<script>
$(document).ready(function() {
var timer = null;
var dataString;
function submitForm(){
alert("success");
$.ajax({ type: "POST",
url: "index.php",
data: dataString,
success: function(result){
alert("success");
/*$('#special').append('<p>' + $('#resultval', result).html() + '</p>');*/
}
});
return false;
}
$('#submit').on('keyup', function() {
clearTimeout(timer);
timer = setTimeout(submitForm, 2000);
var name = $("#name").val();
dataString = 'name='+ name;
});
});
</script>
HTML
<input id="name" name="name" type="text" class="field text medium" value="<? $url ?>" maxlength="255" tabindex="1" />
The problem is that in the HTML above you have
id="name"but are binding to"#submit".You have
id="submit"in your jsfiddle example, which is why it works.