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

JS populating select box--problem

Status
Not open for further replies.

middletree

Programmer
Jul 12, 2007
3
US
I have a <select box that will potentially have several hundred entries, populated from a SQL Server db. The value of each option will be a number, but the part that users will see is a string (person's name). In order to
break up the large list of names, I have links to the left. Each link is one letter of the alphabet. Click the W, and the select box only populates with those whose last name begins with W.

It works fine, but the dropdown as is has a few blank spaces at the top. For example, click the letter W and you'll see a few empty options before the first name in the list. I have been unable to make those extra empty entries disappear. Ideally, I'd like "Select One" to be the pre-selected value.

The page can be viewed at
Please note that there are currently only a few names that populate the dropdown, but in short order, that number will grow to several hundred. For now, click 'G', 'S' or 'W' to see a name show up, and any other letter will have
an empty dropdown. Unless I add some more names after this is posted.
 
Change this:

Code:
frm.MemberName.options[i] = new Option(strFullName, strValue)

to this:

Code:
frm.MemberName.options[[!]i - 1[/!]] = new Option(strFullName, strValue)

Hope this helps,
Dan



Coedit Limited - Delivering standards compliant, accessible web solutions

[tt]Dan's Page [blue]@[/blue] Code Couch
[/tt]
 
Thanks, but the behavior was exactly the same. And yes, I cleared out my cache to make sure I was getting the new changed js file.
 
Resolved by going back to that same line we discussed, and adding a different index. I used the new index in that one line.

thanks very much for your help.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top