proud Posted March 22, 2007 Share Posted March 22, 2007 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 More sharing options...
Kerblam Posted March 22, 2007 Share Posted March 22, 2007 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? Link to comment https://forums.phpfreaks.com/topic/43877-problem-with-the-select-tag/#findComment-212992 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.