HTML/ASP Option Box problem |
HTML/ASP Option Box problem |
cadiaz67 |
Feb 19 2007, 11:02 PM
Post
#1
|
Group: Members Posts: 7 Joined: 30-November 06 Member No.: 1,176 |
I have this problem with my option box.
It's hard to explain but I will give it a try. Example box: <select name="username"> <OPTION value=""><%=username%></OPTION> <OPTION>Pepe</OPTION> <OPTION>Laura</OPTION> <OPTION>Joe</OPTION> <OPTION>Carlos</OPTION> <OPTION>Tom</OPTION> <OPTION>Larry</OPTION> <OPTION>Mike</OPTION> <OPTION>Jeff</OPTION> </SELECT> The value of <%=username%> is always going to be one of the names listed in the option box. When I first load the box the <%=username%> value appears as the selection made automatically. Let's say that the selection value of <%=username%> is Carlos, my problem is that I get two other Carlos listed on the box for the total of three, the Carlos from the <%=username%> value which is already automatically selected, then another right under it and third one which is part of the list for the total of three. This does not look professional. Does anyone knows a way around this? |
Effovex |
Feb 19 2007, 11:29 PM
Post
#2
|
Serious Coder Group: Members Posts: 251 Joined: 6-January 07 From: Sherbrooke, Qc, Canada Member No.: 1,477 |
I assume you're coding in ASP or something like that. Anyway, the best way to do this is to set the value of the option currently selected as "SELECTED" when outputting the page. I'm not familiar with ASP, but I guess it'd look like:
CODE <select name="username"> <OPTION <%= var=="pepe" ? "SELECTED" : "" %>>Pepe</OPTION> <OPTION<%= var=="laura" ? "SELECTED" : "" %>>Laura</OPTION> <OPTION<%= var=="Joe" ? "SELECTED" : "" %>>Joe</OPTION> and so on </SELECT> Option in HTML reference (Note: X ? Y : Z means: if(x) then Y, else Z - it's a common shorthand in programming languages, but I don't know if what you're using supports it) |
cadiaz67 |
Feb 20 2007, 06:16 PM
Post
#3
|
Group: Members Posts: 7 Joined: 30-November 06 Member No.: 1,176 |
I found a solution for my problem:
<select name="username"> <OPTION Value="<%= username %>" selected><%= username %> <%if username <> "Carlos" Then%> <OPTION>Carlos</OPTION> <%End if%> <%if username <> "Berry" Then%> <OPTION>Berry</OPTION> <%end if%> <%if username <> "Larry" Then%> <OPTION>Larry</OPTION> <%end if%> <%if username <> "Betty" Then%> <OPTION>Betty</OPTION> <%End if%> </SELECT> This will prevent the name from appearing more than once in the option box. It is very simple code, but works great! |
Lo-Fi Version | Time is now: 27th April 2024 - 01:18 AM |