Click to See Complete Forum and Search --> : SELECT form problem


ewc21
02-26-2004, 11:37 AM
I am developing a system in ASP where users can edit their details. Among the details they can edit are in the form of drop down menu.

If for example in a member's Country he chose 'Norway.', once he edits his profile the form should automatically be set as

<select name="country">
<option>PLEASE SELECT COUNTRY</option>
.
.
.
<option "Malaysia">Malaysia</option>
<option "Norway" Selected>Norway</option>
<option "Oman">Oman</option>
<option "Peru">Peru</option>
.
.
.
</select>

How do I make such pre defined selected value if I have a variable named country = "Norway"

Hope somebody can help me.

buntine
02-26-2004, 11:46 AM
Hey, this is a common question people ask me.

The easiest way is to run an if statement on each option as follows:

with response
.write ("<option")
if LCase(country) = "norway" then
.write (" selected="selected""")
.write (" value=""Norway"">Norway</option>" & vbCrLf)

.write ("<option")
if LCase(country) = "peru" then
.write (" selected="selected""")
.write (" value=""Peru"">Peru</option>" & vbCrLf)

'Etc, etc...
end with


Hope this helps you out.

Regards,
Andrew Buntine.

buntine
02-26-2004, 11:49 AM
Just an extra note:

The best way to achieve this is to store all the available countries in a Access database and then loop through them using an ADO recordSet loop.
this would prevent alot of un-needed coding.

Or you could store all the countries in an array and then use a for-next loop at run though each one and display an option for each one.

Regards.

ewc21
02-26-2004, 11:54 AM
HI Andrew,

Thank you for your help. I think saving the country list in a database can be a good way to save time later especially that I will be using this field too often.

EWC21

buntine
02-26-2004, 12:08 PM
Yes, it will very time saving. Instead of writing an if statement for wevery country you will only have to do it once.