HTML Select problem ?

JavaScript and client side scripting.

Moderator: General Moderators

Post Reply
NEWDAY
Forum Newbie
Posts: 12
Joined: Wed Jan 31, 2007 5:15 pm

HTML Select problem ?

Post by NEWDAY »

feyd | Please use

Code: Select all

,

Code: Select all

and [syntax="..."] tags where appropriate when posting code. Your post has been edited to reflect how we'd like it posted. Please read:  [url=http://forums.devnetwork.net/viewtopic.php?t=21171]Posting Code in the Forums[/url] to learn how to do it too.[/color]


I'm using a html select tag with the following code:



[syntax="html"]<select  size="1" name="sq"> 
          <option selected>Select One</option>
          <option>Who is your best childhood friend?</option>
          <option>What is your favorite meal?</option>
          <option>What is your favorite hobby?</option>
          <option>Who is your favorite teacher?</option>
          <option>What is your favorite movie?</option>
          </select> 

what I'm trying to do is to set the value of the select tag to the option I want out of these 4 options :

i.e.

Code: Select all

<select  size="1" name="sq"  value="<option> What is your town? </option>" >  

          <option selected>Select One</option>
          <option>What is your father name?</option>
          <option>What is your country?</option>
          <option>What is your town?</option>
       
          </select>
But this doesnt seem to work the value of the select tag is always equal to the first option which is (Select One) so how can I set the value of the select tag to the option I want?


feyd | Please use[/syntax]

Code: Select all

,

Code: Select all

and [syntax="..."] tags where appropriate when posting code. Your post has been edited to reflect how we'd like it posted. Please read:  [url=http://forums.devnetwork.net/viewtopic.php?t=21171]Posting Code in the Forums[/url] to learn how to do it too.[/color]
nickvd
DevNet Resident
Posts: 1027
Joined: Thu Mar 10, 2005 5:27 pm
Location: Southern Ontario
Contact:

Post by nickvd »

Code: Select all

<select  size="1" name="sq">
  <option selected="selected">Select One</option>
  <option value="childhoodfriend">Who is your best childhood friend?</option>
  <option value="favouritemeal">What is your favorite meal?</option>
  <option value="...">What is your favorite hobby?</option>
  <option value="...">Who is your favorite teacher?</option>
  <option value="...">What is your favorite movie?</option>
</select>
User avatar
harrisonad
Forum Contributor
Posts: 288
Joined: Fri Oct 15, 2004 4:58 am
Location: Philippines
Contact:

Re: HTML Select problem ?

Post by harrisonad »

NEWDAY wrote:... so how can I set the value of the select tag to the option I want?
placing the attribute "SELECTED" inside an option tag makes it the default value, as in:

Code: Select all

<option selected>Select One</option>
so removing the SELECTED attribute from the "Select One" option and putting it on other option you want (eg. What is your town?)
will make that option as default value.

Code: Select all

<option>Select One</option>
<option selected>What is your town?</option>
User avatar
mikeq
Forum Regular
Posts: 512
Joined: Fri May 03, 2002 3:33 am
Location: Edinburgh, Scotland

Post by mikeq »

and as nick's code shows, if you want it to be XHTML compliant then

Code: Select all

<option selected="selected">The Option</option>
Post Reply