954,600 Members — Technology Publication meets Social Media
Username:
Password:
Lost login information?
Have something to say? Contribute New Article Reply to this Article

Inserting a blank field in a SELECT tag dropdown box?

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
dhudnall
Newbie Poster
5 posts since Mar 2008
Reputation Points: 10
Solved Threads: 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
dhudnall
Newbie Poster
5 posts since Mar 2008
Reputation Points: 10
Solved Threads: 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

WebspoonUK
Newbie Poster
22 posts since Mar 2010
Reputation Points: 10
Solved Threads: 2
 

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

almostbob
Posting Sensei
3,149 posts since Jan 2009
Reputation Points: 571
Solved Threads: 376
 

This question has already been solved

Post: Markdown Syntax: Formatting Help
You