I have a form that takes a zipcode as input and displays a google map on the same page using ajax.

If I submit the form using a submit button, it works fine.

However, I would like to auto submit the form after 5 characters are entered.

This code works fine to submit the form:

<form id="zip" action="zip.php" method="post">
zip code: <input type="text" name="zipcode" onKeyUp="if(this.value.length>4)this.form.submit()">
</form>

but without using the submit button, it does not query zip.php replace the div on the current page with the google map. All it does is load the action page, zip.php.

Why does it work fine with a submit button, but not with this.form.submit

This has been driving me crazy!

Thank you!

Recommended Answers

try this document.zip.submit();

Jump to Post

All 2 Replies

try this document.zip.submit();

ASG,

Form submission makes a regular (non-ajax) HTTP request so if you want ajax, ensure that the form is not submitted.

If the submit button performs ajax, then the code for onKeyUp should be similar.

Airshow

Be a part of the DaniWeb community

We're a friendly, industry-focused community of 1.20 million developers, IT pros, digital marketers, and technology enthusiasts learning and sharing knowledge.