Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Pass the value of a SELECT to a Javascript function via the onchange event?

I have a HTML page that contains a search box containing a number of textboxes.

The first part of the search box is a SELECT dropdown list that contains a variety of report types. Each report type requires 1 or more of textboxes to be filled in to filter the query results. My goal is hide the textboxes that are not required by the current report type.

How do I pass the currently selected value from the SELECT to the Javascript function via the onchange event?

<select name="report_type" onchange="hide();">
<option value="full_history">Full History</option>
<option value="partial_history">Partial History</option>            
</select>
like image 793
John M Avatar asked Aug 13 '10 16:08

John M


People also ask

How do you pass a value on Onchange?

To pass multiple parameters to onChange in React:Pass an arrow function to the onChange prop. The arrow function will get called with the event object. Call your handleChange function and pass it the event and the rest of the parameters.

How do I write Onchange for select tag?

To handle the onChange event on a select element in React: Set the onChange prop on the select element. Keep the value of the selected option in a state variable. Every time the user changes the selected option, update the state variable.


1 Answers

<select name="report_type" onchange="hide(this.value);">
<option value="full_history">Full History</option>
<option value="partial_history">Partial History</option>            
</select>

When doing this the function have whatever value the select currently has.

like image 141
gabe3886 Avatar answered Oct 17 '22 18:10

gabe3886