Greg's Blog

helping me remember what I figure out

JavaScript: Automatic Submit Using onChange

| Comments

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: [code]
[/code] 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: [code]function AutoSubmit() { document.{your_form_name}.submit(); }[/code] 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!