How can we submit a form without a submit button?
A form can be sent with JavaScript, without a submit button. Use the submit() method of the form, for example from a link click or when a select box changes.
<form id="myForm" method="post" action="process.php">
<input type="text" name="name" value="Robin">
</form>
<a href="#" onclick="document.getElementById('myForm').submit(); return false;">Send the form</a>
<select onchange="this.form.submit()" name="city" form="myForm">
<option>Delhi</option>
<option>Mumbai</option>
</select>
PHP receives the data in the normal way, from $_POST. See PHP Forms Handling.
Note:
Do not name any form field “submit” or “action”. It hides the form method and submit() stops working. Also remember that submit() skips the HTML validation, use requestSubmit() if you want the browser to check the fields first.
Learn more about the similar topics:
| Tutorials |
|---|
| No Content Found. |
| Exercises & Assignments |
|---|
| No Content Found. |
| Interview Questions & Answers |
|---|
| No Content Found. |