|
|
|||||||||
|
|||||||||
| |||||||||
|
|
|
| |||||||||
![]() |
|
|
«
Previous Thread
|
Next Thread
»
|
Thread Tools | Search this Thread | Rate Thread | Display Modes |
|
#1
|
|||
|
|||
|
select an option
Code:
SELECT NAME="time_zone" onchange="checkdisabled(this)"> <option selected>Choose Option</option> <OPTION disabled=true>European <OPTION disabled=true> <OPTION disabled=true>GMT Greenwich Mean Time, as UTC <OPTION>BST British Summer Time, as UTC+1 hour <OPTION>IST Irish Summer Time, as UTC+1 hour <OPTION disabled=true>WET Western Europe Time, as UTC <OPTION>WEST Western Europe Summer Time, as UTC+1 hour <OPTION>CET Central Europe Time, as UTC+1 <OPTION>CEST Central Europe Summer Time, as UTC+2 <OPTION>EET Eastern Europe Time, as UTC+2 <OPTION>EEST Eastern Europe Summer Time, as UTC+3 <OPTION>MSK Moscow Time, as UTC+3 <OPTION>MSD Moscow Summer Time, as UTC+4 <OPTION disabled=true> <OPTION disabled=true>US and Canada <OPTION disabled=true> <OPTION>NST Newfoundland Standard Time, as UTC-3:30 hours <OPTION>NDT Newfoundland Daylight Time, as UTC-2:30 hours <OPTION>AST Atlantic Standard Time, as UTC-4 hours <OPTION>ADT Atlantic Daylight Time, as UTC-3 hours <OPTION>EST Eastern Standard Time, as UTC-5 hours <OPTION>EDT Eastern Daylight Saving Time, as UTC-4 hours <OPTION disabled=true>ET Eastern Time, either and so on and so on you get the point I'm autofilling this form. Typically what i've done is after the option, insert a little asp to check to see what the RS is and response.write "SELECTED" if the option value is = RS value. Is there any all powerfull method i can use to have which option is selected without having to insert 30 million if statements in the option tag? I tried value="blah" and crossed my fingers and that didn't work of course, so anyone else know a way? |
|
#2
|
|||
|
|||
|
<option <% if request.form("D1") <> "" then if RS("dateFlex") = "No" then response.write "SELECTED" end if end if %>>
this is what i've done in the past FYI |
|
#3
|
|||
|
|||
|
Are you dynamically building this <select>...</select>?
If so wouldn't that work? ---------------------------------------------------------- <SELECT NAME="time_zone" onchange="checkdisabled(this)"> <% Dim IsSelected IsSelected = NULL While NOT RS.EOF If Trim(Lcase(RS("dateFlex"))) = "no" Then IsSelected = "SELECTED" End If Response.Write "<option " & IsSelected & ">" & RS("xxx") & "</option>" RS.MoveNext Wend RS.Close Set RS = nothing %> </SELECT> ---------------------------------------------------------- Note the RS("xxx") which represents the value you want to put between the <option>...</option> I've also noticed that you didn't have a value attribute, is that what you want? Hope this helps! Sincerely Vlince |
|
#4
|
|||
|
|||
|
my code is just what it is, i'm not dynamically creating it. It's just a list of all the time zones so that never changes. I was wondering if there's an easier way to select a default value rather than do the if in each option.
|
|
#5
|
|||
|
|||
|
Oh ok, what *I* would do is something like this:
Create a javascript function that builds your <select>...</select> The javascript function would be called on the onload attribute of the <body> tag something like: <body onload="CreateCombobox()"> I would add, a parameter like this: <body onload="CreateCombobox(<%=RS("xxx")%>)"> Remember that you can only have ONE value that is SELECTED inside a <select>...</select> so Then the javascript function, which is defined inside the <head>...</head> section of your code would create the <select>...</select> looking to see if the parameter equals something. If it does, then print the SELECTED When I come to think of it, maybe your approach is better, I mean it's NOT that ugly and most importantly it works right? I'd keep it like that! no? Unless you want to build your <select>...</select> SERVER-SIDE? no? The idea behind the SERVER-SIDE approach *avoids* making the "check" in each <option>...</option> EVEN if your values aren't dynamically driven(they are hard coded as you mention) Hope I makes sense! Sincerely Vlince |
|
#6
|
|||
|
|||
|
yea, i guess i'll just keep it server side, no it's not that ugly, but a pain in the arse to type in. Too many timezones in this world =(
you'd think someone smart would have built in a way to select a specific option in these.... lazy bums, didn't they know other people would be inventing server side languages soon? ![]() |
![]() |
| Viewing: Dev Shed Forums > Programming Languages - More > ASP Programming > select an option |
| Thread Tools | Search this Thread |
| Display Modes | Rate This Thread |
|
|
|
|
|