0

Hello,
I am very new to .asp and I have been tasked with updating a dropdown box in one of our web applications to include a "blank" field at the top of the dropdown box so that if a matching result isn't found, it will default to a blank value instead of the first value in the dropdown box.

The code basically pulls a list of locations from a LOCATION table and populates a dropdown box on a form with the list of locations. It contains logic that checks to see if another location field on the form matches any of the locations in the dropdown box. If it does match, it select "that" location as the default, otherwise, it defaults to the first location. What I would like it to do is default to a blank field if it doesn't match a location on the form. Can anyone please help with this????

set RS = ConnDAT.Execute("select distinct location from location order by location asc")
		
		do while not RS.eof
			location = trim(RS(0))
			Response.Write "<option value='" & PrepareStringForSave(location) & "'"
			if location = tSHIPTO then Response.write " selected"
			Response.Write ">" & location
			RS.MoveNext
		loop
		RS.close
3
Contributors
3
Replies
4
Views
7 Years
Discussion Span
Last Post by almostbob
0

I am sorry, I forgot to post the top part of the code. The complete code is below. Any help would be great.

Response.Write "<tr><td valign=top>Location:</td><td>" & tSHIPTO & "</td><td>"
		Response.Write "<select name=location size=1>"
		set RS = ConnDAT.Execute("select distinct location from location order by location asc")
		
		do while not RS.eof
			location = trim(RS(0))
			Response.Write "<option value='" & PrepareStringForSave(location) & "'"
			if location = tSHIPTO then Response.write " selected"
			Response.Write ">" & location
			RS.MoveNext
		loop
		RS.close
		set RS = nothing
0

If no location is found then it should automatically default to the first entry in the list. If you simply add the following code before your do..while loop it should do the trick: -

Response.Write "<option value=''>&nbsp;</option>"

Hope this helps

0

line 9 in the code of the second post should look something like

Response.Write ">" & location & "</option>"

and there should be a </select> after the loop

Edited by almostbob: n/a

This question has already been answered. Start a new discussion instead.
Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.