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 IamaSherpa on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Accessing Select box value

Status
Not open for further replies.

ChrisQuick

Programmer
Oct 4, 1999
144
US
I have trouble trying to read the value from a select box, and placing the value into a hidden input.

The code I have is a mix of ASP and javaScript.

Here is what creates the select.
<td>
<select name=&quot;txtUser&quot; class=&quot;select&quot;>
<% CustListArray = Session(&quot;CustomerNames&quot;)
If IsArray(CustListArray) Then
For counter = 0 to UBound(CustListArray,2)
Response.Write(&quot;<option value='&quot; & CustListArray(0,counter) & &quot;'>&quot; & CustListArray(0,counter) & &quot;</option>&quot; & Chr(10))
Next
End If
%>
</select>
<input type=&quot;hidden&quot; name=&quot;txtUser_hidden&quot;>
</td>


and here is the javaScript that trys to set the value from the select to another input on submittal of the form:

frm.txtUser_hidden.value=frm.txtUser.selectedIndex.value;


When the form is submitted, and the value of txtUser_hidden
is read with:

strCustomerName = CheckSQL(Request.Form(&quot;txtUser_hidden&quot;))
Response.Write(strCustomerName)

The value comes back as UNDEFINED.

Any thoughts?
 
frm.txtUser.selectedIndex returns an integer (the selected index ;-))
so change the frm.txtUser_hidden.value=frm.txtUser.selectedIndex.value;
to frm.txtUser_hidden.value=frm.txtUser.selectedIndex;

that's all !!
 
Well, what I am trying to get is the value from the select box. I changed it to this:

frm.txtUser_hidden.value=frm.txtUser[frm.txtUser.selectedIndex].value;

and it works now. Thanks
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top