HTML Select input? | Sololearn: Learn to code for FREE!

+1

HTML Select input?

How do I use values from select tags? https://code.sololearn.com/WtylniYEvu2Z/?ref=app edit and send this code. It would help more than trying to explain it to me xD

7/28/2018 1:21:18 AM

Daniel Cooper

11 Answers

New Answer

+11

I believe its better to practice than having someone do it for you but 2 ways. 1) In JS get the value the option tag has. if value == "Red" then do this You would get the element by an id, tag name, etc. 2) add a value attribute in the tag itself. <option value="red"> and in js getAttribute("value") returns that string. I would personally go with option 2

+12

The easiest one https://code.sololearn.com/W6T5Vgf79A5B/?ref=app

+12

Dang I over wrote it! Easy: https://code.sololearn.com/WDdpVN6Fqy9i/?ref=app Harder: https://code.sololearn.com/W7NGBtnRRfd0/?ref=app

+11

Youre welcome and no youre not bothering me at all! :)

+10

Wait.... Youre using select tag sorry xD give the select tag an id, getElementById, id.options[id.selectedIndex].value Thats the best bet if my memory is correct

+10

Oh alright, sorry; I'll make the 2 ways if you want

+10

Alright lol give me a few mins

+3

Well, I personally learn better by reading already written code. Helps me understand better. But thanks!

+2

Thanks. I hope I'm not bothering you at all. It just helps me a lot to see the code.

+1

It would help to see the code. I'm already having trouble xD

+1

https://code.sololearn.com/W6m6M37F5Ihj/?ref=app