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

How to pass on the selected text in a drop down list 1

Status
Not open for further replies.

delorfra

Programmer
Mar 8, 2001
79
FR
In the following code :
<FORM METHOD='POST' ACTION='mypage.asp'>
<SELECT NAME=&quot;MYLIST&quot;>
<OPTION VALUE = &quot;MYVAR&quot;>MYTEXT
</SELECT></FORM>

to retrieve MYVAR in mypage.asp, I use REQUEST.FORM(&quot;MYLIST&quot;). But how to pass on the selected text MYTEXT to mypage.asp in the same time because I need both (myvar being the item code and mytext being the item name/description.

In fact, for the moment I have used VALUE = &quot;MYVAR&quot; & &quot;|&quot; & &quot;MYTEXT&quot; which is a bit awkward.

Thanks
 
There may be an easier may, but try creating a hidden field to store the option value.

Call the javascript function jfnUpdateMyList to update the value of the hidden field when the page is being submitted. In the example below, the page is submitted when you select the &quot;Submit&quot; button.

<%@ Language=VBScript %>
<HTML>
<%
If Request.Form(&quot;mylist&quot;) <> &quot;&quot; then
Response.Write &quot;myList value = &quot; & Request.Form(&quot;mylist&quot;) & &quot;<br>&quot;
Response.Write &quot;myList text = &quot; & Request.Form(&quot;hdnmylist&quot;)
end if
%>

<BODY>
<FORM NAME='myform' METHOD='POST' ACTION='mypage.asp'>
<SELECT NAME='mylist'>
<OPTION VALUE = &quot;MYVAR&quot;>MYTEXT
<OPTION VALUE = &quot;MYVAR2&quot;>MYTEXT2
</SELECT>

<INPUT TYPE='hidden' NAME='hdnmylist'>
<INPUT TYPE='button' value='Submit' ONCLICK='javascript:jfnUpdateMyList();'>
</FORM>

<script language=javascript>

function jfnUpdateMyList()
{
document.forms.myform.hdnmylist.value = document.forms.myform.mylist[document.forms.myform.mylist.selectedIndex].text;
document.forms.myform.submit();
}
</script>


</BODY>
</HTML>
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top