Submit html form on dropdown menu value selection or change using javascript


Posted on : Wed, 29th Jul 15 12:29 pm UTC
2314 votes

If you have a Html (or Html5, JSP, PHP, ASP) page with a form element containing select option and you want to submit the form once a option is selected from the list of the dropdown then you can make use of javaScript.

Lets see how we can do that with an example, We have a text input type and a dropdown option with select options as : add, delete and update. The user would enter a name and select one of the option to submit the from. We have no buttons. We do this using javaScript onchange event and submitting the form using this.form.submit()

File : dropdownexample.html Language : HTML
<html>
<head>
<title>Submit form on Dropdown list select</title>
</head>

<body>


<form method="get">

Name : <input type="text" id="name" name="name" />
<br /><br />

Option : 

<select onchange="this.form.submit()" id="option" name="option">
	<option>Select Option</option>
	<option>Add</option>
	<option>Delete</option>
	<option>Update</option>
</select>

</form>


</body>


</html>


Advertisements





Submit html form on dropdown item select


Submit html form on dropdown item Select

Code2care's mission is to share varied knowledge in technical and non-technical areas gathered during day-to-day learnings and development activities so that our visitors can leverage this portal to find solutions to their queries without re-inventing the wheel. Technical posts include Learnings, Tutorials, Video Tutorials, Code Snippets, Tips-n-tricks.

Follow us : Facebook - Twitter - Google +