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

How to make Drop down retain value after .... 2

Status
Not open for further replies.

DougP

MIS
Dec 13, 1999
5,985
US
when I clik the form Submit the combo box goes back to the default.
How can I make it stay where it is untill something else is picked.

Here is my code:
----------------------
<html>
<%@ Language=VBScript %>
<head>
<title>Tampa Convention Center</title>
</head>
<body>
<%
Dim mouseClickX, mouseClickY, XYNum
mouseClickX = CLng(Request.Form(&quot;x&quot;))
mouseClickY = CLng(Request.Form(&quot;y&quot;))
XYNum = mouseClickX & &quot;-&quot; & mouseClickY
%>
<form action=&quot;TradeShow2003.asp&quot; method=&quot;post&quot;>

<select size=&quot;1&quot; name=&quot;Vendor&quot;>
<option selected>Choose a Vendor</option>

<option value=&quot;280-285&quot;>American CompuSystems 511</option>
<option value=&quot;320-470&quot;>The Academy 503</option>
<option value=&quot;105-410&quot;>AIIM-Gulf Coast Chapter 202</option>

</select>&nbsp; X-Y Values &gt; <input type=&quot;text&quot; name=&quot;XYvalue&quot; Value=&quot;<%=XYNum%>&quot; size=&quot;15&quot;><br>
<input type=&quot;image&quot; src=&quot;images/TpaConCtr.jpg&quot;>
<p>&nbsp;</p>
</form>

<p>Copyright 2001, BarcodeONE Corporation </p>
</body>
</html>
---------------------------------------

TIA
DougP, MCP

Visit my WEB site to see how Bar-codes can help you be more productive
 
I accomplished this by storing the values then using JavaScript to set the drop box with the value.
 
I was looking for a VBScript answer
and a snippet of code Please DougP, MCP

Visit my WEB site to see how Bar-codes can help you be more productive
 
Doug,

Actually, when you press the form submit button, the page should unload from the browser and goes to TradeShow2003.asp Is that the same page ?? Are you posting the form to itself ??

If so, I've got a quick / easy script so your list box will retain the same value. Otherwise, the solution is a bit more complex, but definitely doable.

TW

 
OK, try this.


<html>
<%@ Language=VBScript %>
<% Option Explicit %>
<head>
<title>Tampa Convention Center</title>
</head>
<body>
<%
Dim mouseClickX, mouseClickY, XYNum, m
mouseClickX = CLng(Request.Form(&quot;x&quot;))
mouseClickY = CLng(Request.Form(&quot;y&quot;))
XYNum = mouseClickX & &quot;-&quot; & mouseClickY
%>
<form action=&quot;TradeShow2003.asp&quot; method=&quot;post&quot;>

<select size=&quot;1&quot; name=&quot;Vendor&quot;>
<%
m = &quot; &quot;
''That's a single white space, not an empty string.
IF Request.Form(&quot;Vendor&quot;) = &quot;&quot; THEN
m = &quot; selected &quot;
''Those are single white spaces on each end of selected
END IF
%>

<option<%=m%>>Choose a Vendor</option>
<%
m = &quot; &quot;
IF Request.Form(&quot;Vendor&quot;) = &quot;280-285&quot; THEN
m = &quot; selected &quot;
END IF
%>

<option<%=m%>value=&quot;280-285&quot;>American CompuSystems 511</option>
<%
m = &quot; &quot;
IF Request.Form(&quot;Vendor&quot;) = &quot;320-470&quot; THEN
m = &quot; selected &quot;
END IF
%>

<option<%=m%>value=&quot;320-470&quot;>The Academy 503</option>
<%
m = &quot; &quot;
IF Request.Form(&quot;Vendor&quot;) = &quot;105-410&quot; THEN
m = &quot; selected &quot;
END IF
%>

<option<%=m%>value=&quot;105-410&quot;>AIIM-Gulf Coast Chapter 202</option>

</select> X-Y Values > <input type=&quot;text&quot; name=&quot;XYvalue&quot; Value=&quot;<%=XYNum%>&quot; size=&quot;15&quot;><br>
<input type=&quot;image&quot; src=&quot;images/TpaConCtr.jpg&quot;>
<p> </p>
</form>

<p>Copyright 2001, BarcodeONE Corporation </p>
</body>
</html>

I would still recommend JavaScript. It's a lot less code and a lot cleaner. At any rate, this is what you asked for so it should be pretty self explanatory if you need to expand on it, etc...

Side Note: Always put <% Option Explicit %> at the top of your form. See my example above. This forces ASP to throw an error if you have improperly set a variable. Without it, you'll spend days trying to troubleshoot errors in your code.

TW


 
Ok I'll give it a shot a bit

Thanks for the Option Explicit tip
I really don't like it but it’s probably for the best
It makes you Dim every variable

DougP, MCP

Visit my WEB site to see how Bar-codes can help you be more productive
 
I also had a lot more Options so I moved them to an Access database. And read them in when the page loads.

There should be a way to check which one is selected in a Loop of some kind without having to have a whole slew if &quot;IF&quot; statements, don't you think?

here is that new revised code.
----------------------------
<%
Dim mouseClickX, mouseClickY, XYNum
mouseClickX = CLng(Request.Form(&quot;x&quot;))
mouseClickY = CLng(Request.Form(&quot;y&quot;))
Ven=Request.Form(&quot;Vendor&quot;)
XYNum = mouseClickX & &quot;-&quot; & mouseClickY

Set fp_conn = Server.CreateObject(&quot;ADODB.Connection&quot;)
Set fp_rs = Server.CreateObject(&quot;ADODB.Recordset&quot;)
Set fp_rs2 = Server.CreateObject(&quot;ADODB.Recordset&quot;)

fp_conn.Open Application(&quot;Vendors_ConnectionString&quot;)

SQL_String = &quot;UPDATE [Vendors] SET XYCoords = '&quot; & XYNum & &quot;' WHERE Booth = '&quot; & Ven & &quot;';&quot;
SQL_String2 = &quot;Select * From Vendors;&quot;

fp_rs.Open SQL_String, fp_conn, 1, 3, 1
fp_rs2.Open SQL_String2, fp_conn, 1, 3, 1
%>
<form action=&quot;TradeShow2003.asp&quot; method=&quot;post&quot; name=&quot;FrontPage_Form1&quot;>

<select size=&quot;1&quot; name=&quot;Vendor&quot;>
<option selected>Choose a Vendor</option>
<%fp_rs2.movefirst%>
<%do until fp_rs2.eof%>
<option value=&quot;<%=fp_rs2.fields(&quot;Booth&quot;)%>&quot;><%=fp_rs2.fields(&quot;VendorAndBooth&quot;)%></option>
<%fp_rs2.movenext%>
<%loop%>
</select>
<%
Set fp_rs = Nothing
Set fp_conn = Nothing
%>
--------------------------------------
DougP, MCP

Visit my WEB site to see how Bar-codes can help you be more productive
 
Here you go !!

----------------------------
<%
Dim m
Dim mouseClickX, mouseClickY, XYNum
mouseClickX = CLng(Request.Form(&quot;x&quot;))
mouseClickY = CLng(Request.Form(&quot;y&quot;))
Ven=Request.Form(&quot;Vendor&quot;)
XYNum = mouseClickX & &quot;-&quot; & mouseClickY

Set fp_conn = Server.CreateObject(&quot;ADODB.Connection&quot;)
Set fp_rs = Server.CreateObject(&quot;ADODB.Recordset&quot;)
Set fp_rs2 = Server.CreateObject(&quot;ADODB.Recordset&quot;)

fp_conn.Open Application(&quot;Vendors_ConnectionString&quot;)

SQL_String = &quot;UPDATE [Vendors] SET XYCoords = '&quot; & XYNum & &quot;' WHERE Booth = '&quot; & Ven & &quot;';&quot;
SQL_String2 = &quot;Select * From Vendors;&quot;

fp_rs.Open SQL_String, fp_conn, 1, 3, 1
fp_rs2.Open SQL_String2, fp_conn, 1, 3, 1
%>
<form action=&quot;TradeShow2003.asp&quot; method=&quot;post&quot; name=&quot;FrontPage_Form1&quot;>

<select size=&quot;1&quot; name=&quot;Vendor&quot;>
<%
m = &quot; &quot;
IF Request.Form(&quot;Vendor&quot;) = &quot;&quot; THEN
m = &quot; selected &quot;
END IF
%>

<option<%=m%>>Choose a Vendor</option>
<%fp_rs2.movefirst%>
<%do until fp_rs2.eof%>
<%
m = &quot; &quot;
IF Request.Form(&quot;Vendor&quot;) = Trim(fp_rs2.fields(&quot;booth&quot;))
m = &quot; selected &quot;
END IF
%>

<option<%=m%>value=&quot;<%=fp_rs2.fields(&quot;Booth&quot;)%>&quot;><%=fp_rs2.fields(&quot;VendorAndBooth&quot;)%></option>
<%fp_rs2.movenext%>
<%loop%>
</select>
<%
Set fp_rs = Nothing
Set fp_conn = Nothing
%>

Have a great day !!

TW
 
Try this way :

Code:
<%
    Dim mouseClickX, mouseClickY, XYNum
    mouseClickX = CLng(Request.Form(&quot;x&quot;))
    mouseClickY = CLng(Request.Form(&quot;y&quot;))
    Ven=Request.Form(&quot;Vendor&quot;)
    XYNum = mouseClickX & &quot;-&quot; & mouseClickY 
    
    Set fp_conn =  Server.CreateObject(&quot;ADODB.Connection&quot;)
    Set fp_rs = Server.CreateObject(&quot;ADODB.Recordset&quot;)
    Set fp_rs2 = Server.CreateObject(&quot;ADODB.Recordset&quot;)
    
    fp_conn.Open Application(&quot;Vendors_ConnectionString&quot;)
    
    SQL_String = &quot;UPDATE [Vendors] SET XYCoords = '&quot; & XYNum & &quot;' WHERE Booth = '&quot; & Ven & &quot;';&quot;
    SQL_String2 = &quot;Select * From Vendors;&quot;
    
    fp_rs.Open SQL_String, fp_conn, 1, 3, 1 
    fp_rs2.Open SQL_String2, fp_conn, 1, 3, 1  
%>
    <form action=&quot;TradeShow2003.asp&quot; method=&quot;post&quot; name=&quot;FrontPage_Form1&quot;>
  
       <select size=&quot;1&quot; name=&quot;Vendor&quot;>
          <option selected>Choose a Vendor</option>
          <%fp_rs2.movefirst          
		  do until fp_rs2.eof
			if fp_rs2(&quot;Booth&quot;) = Ven then
		  %>
            <option value=&quot;<%=fp_rs2.fields(&quot;Booth&quot;)%>&quot; SELECTED><%=fp_rs2.fields(&quot;VendorAndBooth&quot;)%></option>
		  <%
		    else
		  %>
			<option value=&quot;<%=fp_rs2.fields(&quot;Booth&quot;)%>&quot;><%=fp_rs2.fields(&quot;VendorAndBooth&quot;)%></option>
	      <%
		    end if
			fp_rs2.movenext
          loop
		  %>
       </select>
<%
     Set fp_rs = Nothing
    Set fp_conn = Nothing
%>
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top