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!

Self post and Select box..?

Status
Not open for further replies.

kenjoswe

Technical User
Sep 19, 2000
327
SE
Hi all,

I have a selfpost asp-page with a select box.
I would like to display the choosen value after the page is submitted.

This is what I have tried so far:
<option value=&quot;<%=Request.Form(&quot;select1&quot;)%>&quot;>*<%=Request.Form(&quot;select1&quot;)%>*</option>

My problem is that the option value is displayed in the select box after the page is submitted instead of the selected Textname.

How can I get both the Optionvalue and the Textname in a select box after the page is posted?

/Kent J.
 
<script language=vbscript>
sub hei_onsubmit
hei.text1.value= hei.select1.options(hei.select1.selectedIndex).text
end sub
</script>
</HEAD>
<BODY>
<form action=test.asp name=hei method=post>
<SELECT id=select1 name=select1>
<OPTION value=1>1. text</OPTION>
<OPTION value=2>2. text</OPTION>
<OPTION value=3>3. text</OPTION>
<OPTION value=4>4. text</OPTION>
</SELECT>
<INPUT type=&quot;hidden&quot; id=text1 name=text1>
<INPUT type=&quot;submit&quot; value=&quot;Submit&quot; id=submit1 name=submit1>
</form>
---
---
---
test.asp:

<form action=test.asp name=hei>
<SELECT id=select1 name=select1>
<OPTION value=1>1. text</OPTION>
<OPTION value=2>2. text</OPTION>
<OPTION value=3>3. text</OPTION>
<OPTION value=4><% response.write Request.Item(&quot;select1&quot;)&&quot;-&quot;&Request.Item(&quot;TEXT1&quot;) %></OPTION>
</SELECT>
<INPUT type=&quot;hidden&quot; id=text1 name=text1>
<INPUT type=&quot;submit&quot; value=&quot;Submit&quot; id=submit1 name=submit1>
</form>

you can also option.value=option.value+option.text in onsubmit. (no use of hidden field)

 
Ingen,

Thanks for your reply.
But your script doesn't seems to do what I'm looking for.

I want the selected item to displayed in the Select box after the page is submitted.

/Kent J.
 
At the of your page, request the value of the select box into a variable:
Code:
varTest=Request(&quot;select1&quot;)

Then, on your select box, check if the variable matches:
Code:
<select name=&quot;select1&quot;>
   <option value=&quot;1&quot; <%if varTest=1 then Response.Write(&quot;Selected&quot;) End if %>>Text 1</option>
</select>

Just do the If variable = value on each option (or in a loop, if you create the select dynamically).

This will display the item that was selected in the select box.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top