Solved

reading text of select box from users selection

Posted on 2004-03-25
8
203 Views
Last Modified: 2012-05-04
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
0
Comment
Question by:tmueller18
  • 4
  • 3
8 Comments
 
LVL 33

Expert Comment

by:hongjun
ID: 10679103
try this

NameofControl.Items[NameofControl.SelectedIndex]
0
 
LVL 33

Expert Comment

by:hongjun
ID: 10679124
html selectbox?
0
 

Author Comment

by:tmueller18
ID: 10679140
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>
0
 

Author Comment

by:tmueller18
ID: 10679258
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?

0
Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

 
LVL 33

Expert Comment

by:hongjun
ID: 10679331
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
0
 
LVL 33

Expert Comment

by:hongjun
ID: 10679335
javascript will solve your problem.
0
 

Author Comment

by:tmueller18
ID: 10679893
i need this one the server side since items are going into a database
0
 
LVL 1

Accepted Solution

by:
ClydeBalneaves earned 500 total points
ID: 10702518
I presume you're ASP.NET?

If so, you need to use .NET controls for serverside, and not just HTML.

ie.

--.aspx file---
<asp:DropDownList id="dropDown" runat="server" Width="176px">
      <asp:ListItem Value="1">one</asp:ListItem>
      <asp:ListItem Value="2">two</asp:ListItem>
</asp:DropDownList>

--.aspx.cs file---
protected System.Web.UI.WebControls.DropDownList dropDown;


Then you can access it like a normal control :

Response.Write(dropDown.SelectedItem.Text);

and

Response.Write(dropDown.SelectedItem.Value);

If you have to use just plain HTML, then I guess setting the value the same as the text is the easiest way to go, if not the only way.

Not sure how much you know about ASP.NET, but remember its served to the user as plain HTML, the code above is purely serverside.
0

Featured Post

Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

Title # Comments Views Activity
Word Directory is not in the drop down list 4 26
Two different visual studio versions 3 23
Not showing page correctly 3 31
Run time Error 4 35
Extention Methods in C# 3.0 by Ivo Stoykov C# 3.0 offers extension methods. They allow extending existing classes without changing the class's source code or relying on inheritance. These are static methods invoked as instance method. This…
Introduction This article series is supposed to shed some light on the use of IDisposable and objects that inherit from it. In essence, a more apt title for this article would be: using (IDisposable) {}. I’m just not sure how many people would ge…
Migrating to Microsoft Office 365 is becoming increasingly popular for organizations both large and small. If you have made the leap to Microsoft’s cloud platform, you know that you will need to create a corporate email signature for your Office 365…
Internet Business Fax to Email Made Easy - With eFax Corporate (http://www.enterprise.efax.com), you'll receive a dedicated online fax number, which is used the same way as a typical analog fax number. You'll receive secure faxes in your email, fr…

863 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

20 Experts available now in Live!

Get 1:1 Help Now