difference between form submitting with ENTER and submit()
Hello!
I'm pretty new to jQuery so maybe everything is working fine as supposed, only I'm waiting for a different result.
I've got a form on my page:
-
<form id="whois" name="searchbox" method="post" action="whois.php">
<input type="text" id="domain-name" name="domain" />
<?php some php code ?>
</form>
I want it to 'auto-submit' itself. This is the code for it:
-
var keyPressed = new Array();
$(document).ready(function(){
$("#domain-name").keydown(function(e) {
keyPressed.push((new Date).getTime());
checking = setInterval("compareTime(keyPressed)",2000);
});
});
function compareTime(keyPressed) {
var currentTime = (new Date).getTime();
if ((currentTime - keyPressed[keyPressed.length-1]) > 1500) {
document.searchbox.submit();
}
}
I would like to display results on the same page with this code:
-
$(document).ready(function(){
$("#domain-name").focus();
$("#whois").submit(function() {
$("#result").fadeIn(1000).html("<h1>some text</h1>");
$("#loading").fadeIn(2500).html('<h3>some text</h3>');
$("#seo-tools").fadeIn(1000).html("<h1>some text</h1>");
$("#seo-description").fadeIn(2500).html("<h3>some text</h3>");
$.ajax({
type: "POST",
url: "whois.php",
data: $("#whois").serialize(),
dataType: "html",
success: function(results) {
$("#loading").fadeIn(500).html("<h3>some text</h3>");
$("#results").fadeIn(1000).html(results);
}
});
return false;
});
});
When I submit the form by pressing ENTER, everything works like I would expect.
When I 'leave' the form to 'auto-submit' itself, the results are displayed on the whois.php page - not in the original, where the form is located.
Please give me Your opinion!
Thank You!