JavaScript: Automatic submit using onChange
To make life a little bit easier for end users when they use our drop down menus in forms we decided to implement a automatic form submission when they had made their choice. This is an easy feature to implement. The first thing to do is to add the onChange event handler to your form and in the case of a drop down menu, you add this to the opening <SELECT> tag, as indicated below:
-
<form method="post"> <select name="{your_select_name}"> <option value="-1">Select something</option> <option value="1">Option 1</option> </select> </form>
Please note that when use the onChange event handler you have to specify the function that is going to be executed. In this case we are going to write a function that submits the form. This is done as follows:
-
function AutoSubmit() {
-
document.{your_form_name}.submit();
-
}
Not much this function is there? Basically we tell the browser to submit the form on this page, when a change to our select box takes place. Simple, when you know how!
About this entry
You’re currently reading “JavaScript: Automatic submit using onChange,” an entry on gregs
- Published:
- Tuesday, October 17th, 2000 at 12:00 am
- Author:
- gregs
- Category:
- JavaScript
No comments
Jump to comment form | comments rss | trackback uri