Page 1 of 1

HTML Select problem ?

Posted: Thu Mar 22, 2007 3:05 pm
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]

Posted: Thu Mar 22, 2007 3:13 pm
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>

Re: HTML Select problem ?

Posted: Thu Mar 22, 2007 7:38 pm
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>

Posted: Fri Mar 23, 2007 2:42 am
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>