How to pass parameters on onChange of html select

Asked
Active3 hr before
Viewed126 times

4 Answers

parametersonchange
90%

<select id="comboA" onchange="getComboA(this)">
   <option value="">Select combo</option>
   <option value="Value1">Text1</option>
   <option value="Value2">Text2</option>
   <option value="Value3">Text3</option>
</select>
load more v
88%

Stack Overflow for Teams Where developers & technologists share private knowledge with coworkers ,How can I pass the complete combobox with its select id, and how can I pass other parameters on fire of the onChange event?, GitLab launches Collective on Stack Overflow , Meta Stack Overflow

function getComboA(selectObject) {
   var value = selectObject.value;
   console.log(value);
}
<select id="comboA" onchange="getComboA(this)">
   <option value="">Select combo</option>
   <option value="Value1">Text1</option>
   <option value="Value2">Text2</option>
   <option value="Value3">Text3</option>
</select>
load more v
72%

But this does not really allow you to specify that argument passed in, so instead you may do this:,If you wanted to get the string "Mr" if the first option was selected (instead of just "1") you would do that in the following way: ,Another approach wich can be handy in some situations, is passing the value of the selected <option /> directly to the function like this:,Just in case someone is looking for a React solution without having to download addition dependancies you could write:

function getComboA(selectObject) {
   var value = selectObject.value;
   console.log(value);
}
<select id="comboA" onchange="getComboA(this)">
   <option value="">Select combo</option>
   <option value="Value1">Text1</option>
   <option value="Value2">Text2</option>
   <option value="Value3">Text3</option>
</select>
load more v
65%

I am a novice at JavaScript and jQuery. I want to show one combobox-A, which is an HTML <select> with its selected id and contents at the other place on onChange(). ,How can I pass the complete combobox with its select id, and how can I pass other parameters on fire of the onChange event?,Select elements typically have two values that you want to access. First there's the value to be sent to the server, which is easy: ,this code once i write for just explain onChange event of select you can save this code as html and see output it works.and easy to understand for you.

function getComboA(selectObject) {
   var value = selectObject.value;
}
<select id="comboA" onchange="getComboA(this)">
   <option value="">Select combo</option>
   <option value="Value1">Text1</option>
   <option value="Value2">Text2</option>
   <option value="Value3">Text3</option>
</select>
load more v

Other "parameters-onchange" queries related to "How to pass parameters on onChange of html select"