Link to home
Start Free TrialLog in
Avatar of tmueller18
tmueller18

asked on

reading text of select box from users selection

i have a simple html selectbox and i can read the selected value no problem. How do i read the text?

something like this?
Request.Form["AFFX"].SelectedIndex.Text ?

im having a complete brain fart today
Avatar of hongjun
hongjun
Flag of Singapore image

try this

NameofControl.Items[NameofControl.SelectedIndex]
html selectbox?
Avatar of tmueller18
tmueller18

ASKER

the error

Compiler Error Message: CS0246: The type or namespace name 'AFFX' could not be found (are you missing a using directive or an assembly reference?)


im using HTML to build the selectbox


<select name='Afil1'>
    <option value="">- Please select affiliate -</option>
    <option value="5517">ABC Affiliate</option>
    <option value="5487">adsfdsfasdfffdddfd</option>
    <option value="5512">Affiliate ABC</option>
    <option value="5515">Affiliate test x</option>
  </select>
i huess i could do something like this

<option value="5517_ABC Affiliate">ABC Affiliate</option>

and then parse out the name from the value.

would I use indeOf in c# for this?

try this piece of code.

<html>

<head>

<script language="JavaScript">
function getValue() {
      alert(document.frmMain.mysel[document.frmMain.mysel.selectedIndex].value);
}


function getText() {
      alert(document.frmMain.mysel[document.frmMain.mysel.selectedIndex].innerHTML);
}
</script>

</head>

<body>
<form name="frmMain">
<select name="mysel">
<option value="1">one</option>
<option value="2">two</option>
<option value="3">three</option>
</select>

<br><br>
<input type="button" value="Get Value" onclick="getValue()">
<br><br>
<input type="button" value="Get Text" onclick="getText()">
</form>
</body>

</html>



hongjun
javascript will solve your problem.
i need this one the server side since items are going into a database
ASKER CERTIFIED SOLUTION
Avatar of ClydeBalneaves
ClydeBalneaves

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial