Jump to content

Problem with the select tag


proud

Recommended Posts

 

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

 

<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 one of these options when a certain condition occurs:

 

i.e.

 

<select  size="1" name="sq" 
<? if  ($questionv!=="Select One") ?> 
value="<option> Who is your best childhood friend? </option>" >  
          <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>

 

 

But this doesnt seem to work so how can I set the value of the select tag to the option I want?

Link to comment
https://forums.phpfreaks.com/topic/43877-problem-with-the-select-tag/
Share on other sites

You were close.

 

<select  size="1" name="sq"> 
          <option>Select One</option>
          <option <?php if (condition) { echo "selected";}?> >Who is your best childhood friend?</option>
          <option <?php if (condition) { echo "selected";}?> >What is your favorite meal?</option>
          <option <?php if (condition) { echo "selected";}?> >What is your favorite hobby?</option>
          <option <?php if (condition) { echo "selected";}?> >Who is your favorite teacher?</option>
          <option <?php if (condition) { echo "selected";}?> >What is your favorite movie?</option>
          </select> 

 

Is this what you meant?

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.