I have a select option tags in my HTML which are populated via api calls
<select name="channel" id="selectName" onChange="getSelectedName(this)">
<option value="">Select Name</option>
</select>
In my JS, I’m getting the values of each option with the following lines of codes
// get selected name
function getSelectedName(selectoption){
let name = selectoption.value;
console.log(name);
}
This log the exact value of the channel in the console which is great.
My Challenge:
I have other functions in my project that need the exact values of the value being generated by that function.
How do I access that exact value globally so as to ingest them into other functions.
What I have done:
I’ve tried making the name global, however I have not had any headway with it.
Thanks in anticipation of your response.
2
Answers
If they are on the same page, you should be able to use
This gets the actual selected value of your
<select>
You can access the
select
element value using getElementById. If you want to run other functions when select event happens use this kind of solutionOr you can use event handler