+ 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 ???
19 ответов
+ 12
https://code.sololearn.com/WYFiraZs7Q51/?ref=app
+ 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 .
+ 9
@Atikrant
You can't use "===" for string value....
+ 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.
+ 9
https://code.sololearn.com/WA3B8jWu560f/?ref=app
Try this one...
+ 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...
+ 8
I know... But it isn't a valid rule ☺️..
+ 7
okay 👍
+ 6
oh in didn't knew about onchange attribute .
+ 6
but that works
try it
+ 6
thanks
+ 6
@Nikky I don't know much in JS. Is there any other way of achieving same ???
+ 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.
+ 5
@Calvin Ok
+ 5
achieving same? but what
+ 3
@Shavkat Turakulov copy cat copy cat never catch a rat. Haha sorry i had to say it
+ 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.
- 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");
}
}