+ 12

Please help !!!!!

https://code.sololearn.com/WXaitc9VjtS1/?ref=app In this code, I have 2 options: 1 and 2. I want to display some specific text when someone click on one and two. For ex, If user select one, I want to display hi and when user select two, I want to display bye. How can I achieve this ???

13th Dec 2017, 12:07 PM
Arushi Singhania
Arushi Singhania - avatar
19 Réponses
13th Dec 2017, 1:12 PM
Nikky Amresh
Nikky Amresh - avatar
+ 12
https://code.sololearn.com/WYFiraZs7Q51/?ref=app
13th Dec 2017, 12:15 PM
Nikky Amresh
Nikky Amresh - avatar
+ 10
add this in HTML : <!DOCTYPE html> <html> <head> <title>Page Title</title> </head> <body"> <select onclick = "Respond()"id = "sel"> <option value = "1"> one </option> <option value = "2"> two </option> </select> </body> </html> And this to js : function Respond() { var val = document.getElementById("sel").value; if(val=="1") { alert("Hi"); } else if(val=="2") { alert("bye"); } } It'll be better if you use additional button for this . Run it , you'll know why I'm saying that .
13th Dec 2017, 12:13 PM
RZK 022
RZK 022 - avatar
+ 9
@Atikrant You can't use "===" for string value....
13th Dec 2017, 12:22 PM
Nikky Amresh
Nikky Amresh - avatar
+ 9
@Arushi Instead of putting a title "Please help !!!", it's better to set a proper title such as "How to display selected option value". This could definitely help you find the solution faster, then "please help" message won't be helping you much. 😊 It also help others to find the similar question and solution easier.
13th Dec 2017, 12:58 PM
Calviղ
Calviղ - avatar
13th Dec 2017, 1:19 PM
Nikky Amresh
Nikky Amresh - avatar
+ 9
@Arushi HTML is just a Mark-up Language... You must need a scripting or programing language for it.. Like : js, php, python, java etc...
13th Dec 2017, 2:34 PM
Nikky Amresh
Nikky Amresh - avatar
+ 8
I know... But it isn't a valid rule ☺️..
13th Dec 2017, 12:27 PM
Nikky Amresh
Nikky Amresh - avatar
+ 7
okay 👍
13th Dec 2017, 12:28 PM
RZK 022
RZK 022 - avatar
+ 6
oh in didn't knew about onchange attribute .
13th Dec 2017, 12:17 PM
RZK 022
RZK 022 - avatar
+ 6
but that works try it
13th Dec 2017, 12:25 PM
RZK 022
RZK 022 - avatar
+ 6
thanks
13th Dec 2017, 1:17 PM
Arushi Singhania
Arushi Singhania - avatar
+ 6
@Nikky I don't know much in JS. Is there any other way of achieving same ???
13th Dec 2017, 2:20 PM
Arushi Singhania
Arushi Singhania - avatar
+ 5
@Nikky I want to display hi and bye like normal text not in alert box. https://code.sololearn.com/Wp52fL1hVL2X/?ref=app For ex, in this code, if you select an option, the text is displayed normally. But I am not able to understand this code fully.
13th Dec 2017, 1:02 PM
Arushi Singhania
Arushi Singhania - avatar
+ 5
@Calvin Ok
13th Dec 2017, 1:05 PM
Arushi Singhania
Arushi Singhania - avatar
+ 5
achieving same? but what
13th Dec 2017, 2:30 PM
RZK 022
RZK 022 - avatar
+ 3
@Shavkat Turakulov copy cat copy cat never catch a rat. Haha sorry i had to say it
19th Dec 2017, 2:50 PM
Derek Leiro
Derek Leiro - avatar
+ 2
@Arushi Singhania, HTML provides the basic structure of sites, which is enhanced and modified by other technologies like CSS and JavaScript.  CSS is used to control presentation, formatting, and layout. JavaScript is used to control the behavior of different elements. It means by using only html, you can create only STATIC sites. But by using JAVASCRIPT, you can make a DYNAMIC website. Code provided by @Nikky Amresh is perfect. You must use JavaScript to solve your problem.
13th Dec 2017, 4:42 PM
Saurabh Verma
Saurabh Verma - avatar
- 2
<!DOCTYPE html> <html> <head> <title>Page Title</title> </head> <body"> <select onclick = "Respond()"id = "sel"> <option value = "1"> one </option> <option value = "2"> two </option> </select> </body> </html> And this to js : function Respond() { var val = document.getElementById("sel").value; if(val==="1") { alert("Hi"); } else if(val==="2") { alert("bye"); } }
13th Dec 2017, 4:03 PM
Shavkat Turakulov
Shavkat Turakulov - avatar