₦airaland Forum

Welcome, Guest: Register • Login • With Google • Trending • Recent • New

Stats: 3,344,736 members, 8,513,448 topics. Date: Thursday, 05 November 2026 at 02:56 AM

Toggle theme

How To Get The Selected Values From Many Options Using Javascript - Programming - Nairaland

Nairaland Forum › Science/Technology › Programming › How To Get The Selected Values From Many Options Using Javascript (1029 Views)

1 Reply (Go Down)

How To Get The Selected Values From Many Options Using Javascript by AloyalNigerian(op): 1:42pm On Oct 21, 2019
Hi all,

I am working on a personal project that requires me to grab the value selected by the user from the drop-down and use that value to in another place probably to display it as a text.


var gender = document.getElementById("btn-wrap"wink;
gender.addEventListener("change", genderGrab, false);

-------------//function genderGrab () {
// let gender = document.getElementById('btn-wrap').elements["choice"].value;

// console.log(gender);
//} .options[gender.selectedIndex] --------------- I tried this method

------------- function genderGrab(e) {
let target = document.getElementById("btn-wrap"wink.elements["choice"];
console.log(target.value);
}-------- and this method.



I was getting errors stating that it can't find the value of undefined. I even tried to see if the eventlistener is working perfectly, and it is.

This issue is giving me tough time even though I am using the value on the same page, imagine whta I am going through trying to use a grabbed value in another page.

I am so sorry if my question is not clear enough but you can always ask for more clarification.

Thanks in advance.
Re: How To Get The Selected Values From Many Options Using Javascript by afuye(m): 2:15pm On Oct 21, 2019
Drop ur number lemme call u
Re: How To Get The Selected Values From Many Options Using Javascript by AloyalNigerian(op): 2:29pm On Oct 21, 2019
afuye:
Drop ur number lemme call u
Is that your number on your signature?
Re: How To Get The Selected Values From Many Options Using Javascript by afuye(m): 4:12pm On Oct 21, 2019
Yeah
AloyalNigerian:
Is that your number on your signature?
Re: How To Get The Selected Values From Many Options Using Javascript by stanliwise(m): 11:09pm On Oct 21, 2019
AloyalNigerian:
Hi all,

I am working on a personal project that requires me to grab the value selected by the user from the drop-down and use that value to in another place probably to display it as a text.


var gender = document.getElementById("btn-wrap"wink;
gender.addEventListener("change", genderGrab, false);

-------------//function genderGrab () {
// let gender = document.getElementById('btn-wrap').elements["choice"].value;

// console.log(gender);
//} .options[gender.selectedIndex] --------------- I tried this method

------------- function genderGrab(e) {
let target = document.getElementById("btn-wrap"wink.elements["choice"];
console.log(target.value);
}-------- and this method.



I was getting errors stating that it can't find the value of undefined. I even tried to see if the eventlistener is working perfectly, and it is.

This issue is giving me tough time even though I am using the value on the same page, imagine whta I am going through trying to use a grabbed value in another page.

I am so sorry if my question is not clear enough but you can always ask for more clarification.

Thanks in advance.
Here is an example
HTML CODE

<select id = "ddlViewBy" >
<option value ="1" >test1 </option>
<option value ="2" selected ="selected" > test2 </
<option value ="3" >test3 </option>
</select>

Running this code:
let target= document.getElementById( "ddlViewBy" );
let value = target.options[target.selectedIndex].value;
1 Reply

Getting The N-largest Values From A Dataframe With Grouping - Youtube Video • How To Display Uploaded Image In Html Using Javascript • How To Upload Files To Firebase Cloud Storage Using Javascript • 2 • 3 • 4

Top Recommended AI Articles To Read During Lockdown • I Need Help With My Whatsapp Messenger. • Finding Specific User Posts In Chosen Threads - Google Search.