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

Item selected displayed in drop-down

Status
Not open for further replies.

breeb

Programmer
Jul 8, 2003
25
ZA

I have search that gets input from 3 drop-down boxes and one text box. The results of the search are displayed 5 at a time and therefore I need the results of the search to be displayed in the drop-down box as the user pages through the search results. At the moment I have am using request.querystring to display what was selected, but this is not correct as two copies of the selected option as displayed.

This is what I have:

<b>Unit Name</b>           
<select size=&quot;1&quot; name=&quot;D1&quot; onchange = &quot;unitsubmit()&quot;>
<option selected><%response.write request.querystring (&quot;D1&quot;)%></option>

<%
'first drop down
If RS.EOF and RS.BOF Then
Response.Write &quot;There are 0 records.&quot;
Else
RS.MoveFirst
While Not RS.EOF%>

<option><%Response.Write RS.Fields(&quot;UnitName&quot;)%></option>
<%RS.MoveNext
Wend
End If
RS.Close
%>
</select><br>

<font size=&quot;2&quot;>
<b>Group Name</b>       
<select size=&quot;1&quot; name=&quot;D2&quot;>
<option selected><%response.write request.querystring (&quot;D2&quot;)%></option>

<%
'second drop down box
If RS1.EOF and RS1.BOF Then
Response.Write &quot;There are 0 records.&quot;
Else
RS1.MoveFirst
While Not RS1.EOF%>

<option><%Response.Write RS1.Fields(&quot;GroupName&quot;)%></option>
<%RS1.MoveNext
Wend
End If
RS1.Close
%>
</select><br>

<font size=&quot;2&quot;>
<b>Problem Type</b>      
<select size=&quot;1&quot; name=&quot;D3&quot;>
<option selected><%response.write request.querystring (&quot;D3&quot;)%></option>
<option>Batch</option>
<option>Online</option>
<option>System</option>
<option>Other</option>

</select><br><br>

<input type=&quot;text&quot; name=&quot;T1&quot; size=&quot;32&quot; value = &quot;<%response.write request.querystring (&quot;T1&quot;)%>&quot;><br>
<input type=&quot;submit&quot; value=&quot;GO&quot; name=&quot;B3&quot;><br><br>

Any suggestions would be appreciated!
 
Here is something somewhat similar that I have done which is a Sort By listbox at the top of the page. Instead of using a querystring I used a post. Hope this might give you some ideas as your situation seems similar but just with more listboxes and a textbox and it's for criteria instead of sort order.

You might wish to have a listbox that allows the user to sort the records shown on the page by things like the Name, City, or Zip.

First note that the form is set to submit to itself:
<form id=&quot;frmMain&quot; name=&quot;frmMain&quot; action=&quot;<%= Request.ServerVariables(&quot;SCRIPT_NAME&quot;) %>&quot; method=&quot;post&quot;>

And note that the Sort listbox's onchange event triggers a form submit:
Sort By
<select name=&quot;Sort&quot; size=&quot;1&quot; onchange=&quot;document.frmMain.submit();&quot;>
<option value=&quot;Name&quot;>Name
<option value=&quot;City&quot;>City
<option value=&quot;Zip&quot; selected>Zip
</select>

Toward the top of the VBScript code on the page set a variable called Sort:
' If there was a post, get the Sort, otherwise the Sort should be Name.
If Request.TotalBytes > 0 Then ' Or this could be If Request.Form(&quot;Sort&quot;) <> &quot;&quot; Then
Sort = Request.Form(&quot;Sort&quot;)
Else
Sort = &quot;Name&quot;
End If

And the SQL statement's ORDER BY clause would be based on the posted form value of the Sort listbox. And note that secondary sorts are also used so that if the sort is to be the city that those within the same city are sorted by name:
strSQL = &quot;SELECT * FROM MyTable &quot;
If Sort = &quot;Name&quot; Then
strSQL = strSQL & &quot;ORDER BY LName, FName&quot;
Elseif Sort = &quot;City&quot; Then
strSQL = strSQL & &quot;ORDER BY City, LName, FName&quot;
Elseif Sort = &quot;Zip&quot; Then
strSQL = strSQL & &quot;ORDER BY Zip, LName, FName&quot;
End If

Best regards,
J. Paul Schmidt, Freelance ASP Web Developer
ASP Design Tips, ASP Web Database Demo, Free ASP Bar Chart Tool...
 
Thanks for your reply.

I'm not too clear about two parts of your code:
1) action=&quot;<%= Request.ServerVariables(&quot;SCRIPT_NAME&quot;) %>&quot; method=&quot;post&quot;>
2)If Request.TotalBytes > 0 Then ' Or this could be If Request.Form(&quot;Sort&quot;) <> &quot;&quot; Then
Sort = Request.Form(&quot;Sort&quot;)
Else
Sort = &quot;Name&quot;
End If

What do they do?

 
try this:
Code:
<%
d1=request.querystring (&quot;D1&quot;)
%>
<select size=&quot;1&quot; name=&quot;D1&quot; onchange = &quot;unitsubmit()&quot;>
</option>

    <%
        'first drop down
        If RS.EOF and RS.BOF Then
        Response.Write &quot;There are 0 records.&quot;
        Else
            RS.MoveFirst
            While Not RS.EOF
              sel=&quot;&quot;
              if(RS.Fields(&quot;UnitName&quot;)=d1) then
                sel=&quot;selected&quot;
               end if
%>
                
              <option <%=sel%>><%Response.Write RS.Fields(&quot;UnitName&quot;)%></option>
              <%RS.MoveNext
              Wend
          End If
          RS.Close
      %>
    </select><br>

is this what u want?

Known is handfull, Unknown is worldfull
 
Thanks! Couldn't figure it out first because the drop down had an option selected when the page first loaded, but then realised that there was just an <option> tag left out above.


Much apppreciated.
 
<<
Thanks for your reply.

I'm not too clear about two parts of your code:
1) action=&quot;<%= Request.ServerVariables(&quot;SCRIPT_NAME&quot;) %>&quot; method=&quot;post&quot;>
2)If Request.TotalBytes > 0 Then ' Or this could be If Request.Form(&quot;Sort&quot;) <> &quot;&quot; Then
Sort = Request.Form(&quot;Sort&quot;)
Else
Sort = &quot;Name&quot;
End If

What do they do?
>>

1) Posts the page back to itself.

2) Sets the Sort variable to be whatever was in the listbox if there was a post, otherwise sets it to be &quot;Name&quot;

Best regards,
J. Paul Schmidt, Freelance ASP Web Developer
ASP Design Tips, ASP Web Database Demo, Free ASP Bar Chart Tool...
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top