I have a form in my page like the one below;
<form name="testform" id="testform" action="test.php" method="get">
<input name="field1" id="field1" type="text" value="">
<input name="field2" id="field2" type="text" value="">
<select name="dropdown" id="dropdown">
<option value="option1" selected="selected">option1</option>
<option value="option2">option2</option>
<option value="option3">option3</option>
</select>
<input type="submit" name="Submit" value="Submit" id="Submit">
</form>
I want the form to get submitted automatically when user select an option from the drop-down menu. How can I do this with or without using JavaScript (with or without jQuery)?
Thanks in advance... :)
blasteralfred
I have a form in my page like the one below;
<form name="testform" id="testform" action="test.php" method="get">
<input name="field1" id="field1" type="text" value="">
<input name="field2" id="field2" type="text" value="">
<select name="dropdown" id="dropdown">
<option value="option1" selected="selected">option1</option>
<option value="option2">option2</option>
<option value="option3">option3</option>
</select>
<input type="submit" name="Submit" value="Submit" id="Submit">
</form>
I want the form to get submitted automatically when user select an option from the drop-down menu. How can I do this with or without using JavaScript (with or without jQuery)?
Thanks in advance... :)
blasteralfred
Share Improve this question edited Jul 16, 2012 at 14:49 Alfred asked Mar 17, 2011 at 16:02 AlfredAlfred 21.4k63 gold badges174 silver badges257 bronze badges4 Answers
Reset to default 10Click (or select)? In that case the user would not be able to make any selection. You probably mean as soon as another option is selected. If so
<select name="dropdown" id="dropdown" onchange="this.form.submit()">
If jQuery is being used, unobtrusive event handler change should be used instead of inline javascript.
$(function(){
$("#dropdown").change( function(e) {
this.form.submit();
});
});
Use on if the form elements are dynamically being added in the DOM
$(function(){
$('#testform').on( "change", "#dropdown", function(e) {
this.form.submit();
});
});
You will need to use the jQuery change() event.
('#dropdown').change( function() { ('#testform').submit(); })
I think
$('#dropdown').change(function () { $('Submit').click(); } );
will do the trick!
Here Answer
<form name="testform" id="testform" action="test.php" method="get">
<input name="field1" id="field1" type="text" value="">
<input name="field2" id="field2" type="text" value="">
<select name="dropdown" id="dropdown" onChange="document.testform.submit()">
<option value="option1" selected="selected">option1</option>
<option value="option2">option2</option>
<option value="option3">option3</option>
</select>
</form>