This is my code. How to click automatically submit button after selecting dropdownlist value?
<form action="<?php echo htmlspecialchars($_SERVER["PHP_SELF"]);?>" method="GET" name="form1" class="style1" id="form1">
<p align="center">Select Section
<select name="section" required ><option selected="selected" disabled="disabled">Select Section</option>
<option>ALL</option>
<option>RWS</option>
<option>Structure</option></select>
From
<input name="fromdate" type="date" placeholder="YYYY-DD-MM" required id="mydate" data-lang="en" data-years="2014-2050" data-format="YYYY-MM-DD"/>
To
<input name="todate" type="date" placeholder="YYYY-DD-MM" required id="mydate1" data-lang="en" data-years="2015-2055" data-format="YYYY-MM-DD"/>
<input name="submit" type="submit" id="submit" value="SHOW" />
</p>
You will need to bind onchange event and call submit method of the HTMLFormElement:
$('#form1 select').on('change', function() {
this.form.submit();
});
Important detail. Rename your submit button, you don't want it to have name submit
because this.form.submit
will point to HTMLButtonElement object in this case, while you want it to be a submit methods of the form element:
<input name="submit-btn" type="submit" id="submit-btn" value="SHOW" />
You have not given dropdown code here, hence I am assuming and writing:
<select name="drpdwn" onclick="submitForm()">
<option value="opt1">Option1</ option>
<option value="opt2">Option2</option>
</option>
<script>
function submitForm(){
document.getElementById('formid').submit();
}
</script>
Seem you want to trigger event click on the button.
$('#form1 select').on('change', function() {
$('#submit').trigger('click');
});
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.