Welcome, Guest: Register On Nairaland / LOGIN! / Trending / Recent / New
Stats: 3,155,567 members, 7,827,137 topics. Date: Tuesday, 14 May 2024 at 07:47 AM

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 (869 Views)

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)

(1) (Reply) (Go Down)

How To Get The Selected Values From Many Options Using Javascript by AloyalNigerian(m): 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(m): 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 Like

(1) (Reply)

Help Get My Gmail Account Back Please / Hiring!!! Backend Dev / Get This Module Done And Get Paid

(Go Up)

Sections: politics (1) business autos (1) jobs (1) career education (1) romance computers phones travel sports fashion health
religion celebs tv-movies music-radio literature webmasters programming techmarket

Links: (1) (2) (3) (4) (5) (6) (7) (8) (9) (10)

Nairaland - Copyright © 2005 - 2024 Oluwaseun Osewa. All rights reserved. See How To Advertise. 15
Disclaimer: Every Nairaland member is solely responsible for anything that he/she posts or uploads on Nairaland.