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!

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 developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.