Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations strongm on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

get clicked value of a listbox

Status
Not open for further replies.

sweetleaf

Programmer
Jan 16, 2001
439
CA
Hello,

I have a list box filled with names. I want to be able to click on a name and display the name in a message box.
Does anyone know how to do that?

for ex:

<script language-vbscript>
'userz is name of listbox
sub userz_onclick()
aa = window.frm1.userz.(what goes here?)
msgbox(aa)
end sub

</script>
 
.(what goes here?)

.text

That's javascript solution for sure. I think it works in client side vbscript, too, though.

:)
Paul Prewett
penny.gif
penny.gif
 
hi link9,

in javascript &quot;.text&quot; gives me the following error:&quot;undefined&quot; in the alert box

in vbscript &quot;.value&quot; gives me a blank in the message box

i've tried everything from .innerText to .selectedIndex - still no..

thanks,
mark
 
To find the value of a selected list box, use the following:

Fengshui_1998


<head>
<script language=&quot;javascript&quot;>
<!--
function HandleChange() {
var par1 = document.formname.select.options[document.formname.select.selectedIndex].value;
alert(par1);
}
//-->
</script>
</head>

<body>
<select name=&quot;select&quot; size=&quot;1&quot; OnChange=&quot;HandleChange()&quot;>
<option value=&quot;test1&quot;>test1</option>
<option value=&quot;test2&quot;>test2</option>
<option value=&quot;test3&quot;>test3</option>
</select>
</body>
 
Sorry about that -- vb, vbscript, javascript... what's the difference, right? ;-)

I worked up a very simplified example that will help you:

<html>
<head>
<title>test</title>
<script>
function writeIt(){
document.theForm.textField.value = document.theForm.select.options[0].text;
}
</script>
</head>
<body>
<form name=theForm>
<select name=select>
<option value=1>One</option>
</select>
<input type=text name=textField>
<input type=button value=clickMe onClick=&quot;writeIt();&quot;>
</form>
</body>
</html>

:)
Paul Prewett
penny.gif
penny.gif
 
Hi Link9,

It makes a difference depending on what browser the client is using. NS does not understand VBSCRIPT.

Fengshui_1998
 
I don't think anyone has given the exact VBScript solution for what Sweetleaf asked, so here's my two cents worth:

Code:
sub userz_onclick()
    Dim aa
    aa = window.frm1.userz.options(window.frm1.userz.SelectedIndex).value
    msgbox(aa)
end sub
 
You may want to replace &quot;value&quot; with &quot;Text&quot; from GlennBSI's reply. Just thought I'd throw that in just in case.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top