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!

Drop Down from DB works, BUT input disappears!!!!

Status
Not open for further replies.

DefinityCorporation

IS-IT--Management
Sep 26, 2002
22
US
Hey guys, I have 2 drop downs from DB. "Company_ID" & "Location1" the first displays a list of our customer's company names and the second then shows a list of their employees. So I select "Microsoft" from box1 and then box2 is populated with "Bill Gates, Steve Balmer, Etc. Everything works BUT when I click the company name, and the page refreshes, the company name in first box disapears! So my question is: How do I put the company name back in the drop down during the OnChange=Submit??? Also, any comments on this code/method would be VERY helpfull because this is only my second week in ASP!

Info: Win2k server, IIS 5.0, SQL2k.
company_id = integer (1,2,3)
location1 = company name (microsoft, intel, xyz)

Heres the relevant part:

<FORM METHOD=&quot;POST&quot; NAME=&quot;Form1&quot; ACTION=&quot;newprinter.asp&quot;>
<SELECT NAME=&quot;Company&quot; SIZE=&quot;1&quot; ONCHANGE=Form1.submit()>
<option selected value=&quot;<% = Request.Form(&quot;location_1&quot;) %>&quot;><% = Request.Form(&quot;location_1&quot;) %></option>
<%
' Get list of Companies to diplay
Dim rstCompany
Set rstCompany = SQLQuery(cnnDB, &quot;SELECT DISTINCT company_id, location1 FROM tblusers WHERE company_id > 0 ORDER BY location1 ASC&quot;)
If not rstCompany.EOF Then
Do While Not rstCompany.EOF
%>
<option value=&quot;<% = rstCompany(&quot;company_id&quot;)%>&quot;>
<% = rstCompany(&quot;location1&quot;) %>
</option>
<%
rstCompany.MoveNext
Loop
End If
%> </select></td>
</tr>
</form>
</SELECT>
<FORM METHOD=&quot;POST&quot; NAME=&quot;Form2&quot; ACTION=&quot;newprinter.asp&quot;>
<input type=&quot;hidden&quot; name=&quot;save&quot; value=&quot;1&quot;>
<input type=&quot;hidden&quot; name=&quot;etype&quot; value=&quot;3&quot;>
<tr>
<td width=&quot;168&quot; align=&quot;left&quot; height=&quot;25&quot;>
<b><%=lang(cnnDB, &quot;SelectUser&quot;)%>:</b>
</td>
<td width=&quot;250&quot; align=&quot;left&quot; height=&quot;25&quot;>
<select name=&quot;uselectid&quot;>
<option value=&quot;0&quot; selected><%=lang(cnnDB, &quot;SelectUser&quot;)%></option>
<%
' Get list of users to diplay
Dim rstUser
Set rstUser = SQLQuery(cnnDB, &quot;SELECT * FROM tblUsers WHERE company_id = '&quot; & Request.Form(&quot;Company&quot;) & &quot;'&quot;)
If not rstUser.EOF Then
Do While Not rstUser.EOF
%>
<option value=&quot;<% = rstUser(&quot;sid&quot;)%>&quot;>
<% = rstUser(&quot;uid&quot;) %> (<% = rstUser(&quot;fname&quot;) %>)
</option>
<%
rstUser.MoveNext
Loop
End If
%>
</select>
 
in the loop for filling up the company drop box, put a conditional to check against request(&quot;company&quot;) if they're the same do <option selected value=&quot;<%=Company%>&quot;>

otherwise leave &quot;selected&quot; out that way the previous value passed from the page before is showing
 
I really appreciate your help, but I have tried what you said for 2 hours, and I just cant get it. When I remove the &quot;selected&quot; option, A company name does stay in the drop box 1, but no matter which Company I select, it reverts back to the default company even though the users in box 2 are from the company I selected. I guess I am too green to understand. Could you give me a small code example? Thanks!
 
and it would be greatly recommended to make them both part of the same form due to when you submit form1, yes you populate form2, but unless you're passing a hidden value or something in form2, when it is submitted, old contents for form1 are lost

<%
Company = Request(&quot;Company&quot;)
Set RS = Connection.Execute(&quot;select distinct Company from TABLE where Company is not null and company not like ''&quot;)
%>
<select name=&quot;Company&quot; onchange=&quot;javascript:submit();&quot;>
<option></option>
<%
Do While not RS.EOF
If strComp(RS(&quot;Company&quot;),Default,vbTextCompare) > 0 Then
OptSelVal = &quot; selected&quot;
Else
OptSelVal = &quot;&quot;
End If
%>
<option value=&quot;<%=RS(&quot;Company&quot;)%>&quot;<%=OptSelVal%>><%=RS(&quot;Company&quot;)%></option>
<%
RS.MoveNext
Loop
%>
</select>
Set RS = nothing
<%
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top