Last active
June 8, 2020 11:34
-
-
Save nastanford/7471255 to your computer and use it in GitHub Desktop.
Using JavaScript get the Text or Value of a Selected Item in a Select Box.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
function getSelectedText(){ | |
var e = document.getElementById("nameSelect"); | |
var dspText = e.options[e.selectedIndex].text; | |
return dspText; | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
function getSelectedValue(){ | |
var e = document.getElementById("nameSelect"); | |
var dspValue = e.options[e.selectedIndex].value; | |
return dspValue; | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<html> | |
<head> | |
<title>Test JavaScript</title> | |
</head> | |
<body> | |
<select id="nameSelect" onchange="example()"> | |
<option value="1">Jim</option> | |
<option value="2">Tom</option> | |
<option value="3">Sally</option> | |
</select> | |
</body> | |
</html> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
function example(){ | |
var e = document.getElementById("nameSelect"); | |
var dspText = e.options[e.selectedIndex].text; | |
var dspValue = e.options[e.selectedIndex].value; | |
alert(dspText+' = '+dspValue); | |
} |
No problem
…On Mon, Jun 8, 2020, 12:47 AM ArneSaknussemm ***@***.***> wrote:
***@***.**** commented on this gist.
------------------------------
Thanks!
—
You are receiving this because you authored the thread.
Reply to this email directly, view it on GitHub
<https://gist.github.com/7471255#gistcomment-3333936>, or unsubscribe
<https://github.com/notifications/unsubscribe-auth/AANMWK4VLWM6NPYEADKIBG3RVRUNXANCNFSM4NX63WLQ>
.
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Thanks!