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

Preserving a Form info 2

Status
Not open for further replies.

vias

Programmer
Apr 25, 2000
54
GB
I have the following form which accepts
- an email adress &
- city

=======================================================
<form method=&quot;post&quot; ID=&quot;Form2&quot;>
<TABLE id=&quot;Table1&quot; cellSpacing=&quot;0&quot; cellPadding=&quot;4&quot; width=&quot;100%&quot; border=&quot;0&quot;>
<TR>
<TD valign=&quot;top&quot;>
<%if isBlankError then Response.Write &quot;<font color=red><b>You have not filled all the required fields! </b></font>&quot;
end if%>
<table border=&quot;0&quot; cellspacing=&quot;0&quot; cellpadding=&quot;5&quot;align=&quot;center&quot; ID=&quot;Table5&quot;>

<TR>
<TD width=150 valign=&quot;top&quot; class=&quot;bold&quot;>Your Email Address:</TD>
<TD width=&quot;311&quot;> <INPUT id=&quot;Text5&quot; value=&quot;<%=email%>&quot; type=&quot;text&quot; size=&quot;25&quot; name=&quot;email&quot;>
<FONT color=&quot;#660000&quot;> *</FONT> </TD>
<TD><%=emailAddressErrorHTML%></TD>
</TR>

<TR>
<TD width=150 valign=&quot;top&quot; class=&quot;bold&quot;>  City:</td>
<TD>
<SELECT id=&quot;Select2&quot; size=&quot;1&quot; name=&quot;ct&quot; style=&quot;width:150; font-size: 10px&quot;><OPTION value=&quot;&quot;>Any</OPTION>
<%=getDropdownCity()%>
</SELECT>  <FONT color=&quot;#660000&quot;></FONT>
</TD>
</TR>

</table>

<INPUT id=&quot;Reset1&quot; type=&quot;reset&quot; value=&quot;Reset&quot; name=&quot;reset&quot;>
<INPUT id=&quot;Submit1&quot; type=&quot;submit&quot; value=&quot;Submit&quot; name=&quot;submit&quot;>

</TD>
</TR>
</TABLE>
</form>
======================================================

When i press the <submit> button after choosing a
a city from the dropdown function 'getDropdownCity'
the form gives an error saying I havn't entered an
email address. This is expected. But my chosen city
is replaced by 'Any'.

What I need is for my chosen city from the dropdown to
be preserved. I'll only have to enter my email address.

Can anybody help.

Thanks
 
Hey vias,

I do that like this:
Code:
<Select id=&quot;Select2&quot;  size=&quot;1&quot; name=&quot;ct&quot; style=&quot;width:150; font-size: 10px&quot;><OPTION value=&quot;&quot;>Any</OPTION>
<%
do while NOT city.eof
  response.write &quot;<option value=&quot; & city(&quot;cityID&quot;) 
  if int(city(&quot;cityID&quot;)) = Oid then
    response.write &quot; selected &quot;
  end if	
  response.write &quot;>&quot; & city(&quot;cityName&quot;) & &quot;</option>&quot;
  city.movenext
loop
%>		  
</select>

This assumes that you know what the previously selected City was and have set OID to that value. This example uses City(&quot;cityID&quot;) as the recognized value but it could be anything. The idea is to watch for the previously selected value as you loop through your selections. When you find it; insert the word &quot;selected&quot; that way it will be selected. I use this all the time. If you have any trouble getting it to work let me know I'll take another look at it.

Hope it helps.


Travis Hawkins
BeachBum Software
travis@cfm2asp.com
 
Travis,

Thanks.

I'm still having some problems. Here is the code
of the function which I call. This gives more info
of the way i am doing it.
--------------------------------------------------------
function getDropdownCity()

Dim desc, rs1, strsql,conn
set Conn = server.createobject(&quot;ADODB.Connection&quot;)
conn.open &quot;Provider=Microsoft.Jet.OLEDB.4.0; Data Source=c:\inetpub\test.mdb; User Id=admin; Password=;&quot;

Set rs1 = Server.CreateObject(&quot;ADODB.Recordset&quot;)

if isobject(rs1) then
strsql = &quot;SELECT city from locations;&quot;
set rs1 = conn.execute(strSQL)
do until rs1.eof

desc = desc & &quot;<OPTION value='&quot; & rs1(&quot;city&quot;) & &quot;'&quot; & &quot;>&quot; & rs1(&quot;city&quot;) & &quot;</opt&quot; & &quot;ion>&quot;
rs1.moveNext
loop
end if

getDropdownCity = desc
rs1.Close
set rs1=nothing
conn.Close
end function
-----------------------------------------------------

Looking forward to having your feedback.

Thanks again.
Vias
 
OK vias,

This line is where you need to change:
Code:
desc = desc & &quot;<OPTION value='&quot; & rs1(&quot;city&quot;) & &quot;'&quot;     &quot;>&quot;  &  rs1(&quot;city&quot;) & &quot;</opt&quot; & &quot;ion>&quot;
you need to insert the word &quot;Selected&quot; after the value but still inside the <option> tag. eventually it will look like this:
<option value=&quot;Ohio&quot; selected>Ohio</option>

so to do that use ASP like this:
Code:
desc = desc & &quot;<OPTION value='&quot; & rs1(&quot;city&quot;) & &quot;'&quot;  
if rs1(&quot;city&quot;) = PreviousCityName then
  desc = desc & &quot; selected &quot;
end if  
desc = desc & &quot;>&quot;  &  rs1(&quot;city&quot;) & &quot;</option>&quot;

does that make sense? the variable that I called &quot;PreviousCityName&quot; has to hold the name it was before, the one you want it to select again. I don't know how you are gathering that so I can't be more specific but this should get you started.

If it still doesn't work for you then let me know how you are getting the data back to your script. Maybe that part needs work.

Have fun.



Travis Hawkins
BeachBum Software
travis@cfm2asp.com
 
You'll have to get rid of the function or pass the value of request.form(&quot;ct&quot;) to it. Try doing it inline like this:

<% ' At the top of your form

ct = request.form(&quot;ct&quot;)


' then build your select and compare the value of ct to city
%>

<SELECT id=&quot;Select2&quot; size=&quot;1&quot; name=&quot;ct&quot; style=&quot;width:150; font-size: 10px&quot;><OPTION value=&quot;&quot;>Any</OPTION>
<%
set Conn = server.createobject(&quot;ADODB.Connection&quot;)
conn.open &quot;Provider=Microsoft.Jet.OLEDB.4.0; Data Source=c:\inetpub\test.mdb; User Id=admin; Password=;&quot;
strSql=&quot;SELECT city FROM locations&quot;
set rs1=conn.execute(strSql)

If not rs1.eof then
do until rs1.eof
city=rs1(&quot;city&quot;)%>
<OPTION value=&quot;<%=city%>&quot; <%if city=ct then%>SELECTED<%end if%>><%=city%></option>
<%
rs1.moveNext
loop
end if
set rs1=nothing
conn.Close
set conn=nothing
%>
</SELECT>
 
Travis & Veep,

Thanks for your feedback.

I am still getting 'Any' in my dropdown
after selecting a city and pressing the
submit button.

I must be missing something.

Any ideas?

Thanks
Vias
 
Travis & Veep,

Got it working.
Your feedback were most helpful.

Thanks a lot.
Vias
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top