...

View Full Version : Select form field woe



Jeewhizz
06-22-2002, 08:10 PM
if i have a drop down form field like this...

<select name="rating">
<option value="G">G</option>
<option value="PG">PG</option>
<option value="PG-13">PG-13</option>
<option value="R">R</option>
<option value="NC-17">NC-17</option>
<option value="Unrated">Unrated</option>
<option value="Not MPAA rated">Not MPAA rated</option>
</select>

How can i use javascript to ensure that say.. PG-13 is selected as default, and another time Unrated is? I have the value of the <option..> as a PHP variable, so i can just echo it into the page before it gets to the client

Something like

<script>
document.form.select.selected=="PG-13"
</script>

Cheers

Jee

joh6nn
06-22-2002, 08:15 PM
i think it's

document.form.select.options[phpVariable].selected = true;

premshree
06-24-2002, 06:44 AM
Hello,

You can use the select tags like this

<select name="rating">
<option value="G">G</option>
<option value="PG">PG</option>
<option value="PG-13" selected>PG-13</option>
<option value="R">R</option>
<option value="NC-17">NC-17</option>
<option value="Unrated">Unrated</option>
<option value="Not MPAA rated">Not MPAA rated</option>
</select>

i.e whichever option you want just add the word 'selected' in the <option> tag

Íkii
06-24-2002, 07:43 PM
Or array write the lot

$certi = Array("G","PG","PG-13","R","NC-17","Unrated","Not MPAA rated");

echo '<select name="rating">';

for($cwr=0;$cwr<count($certi);$cwr++) {
echo '<option value="'.$certi[$cwr].'"';
if($certi[$cwr] == $TESTVAR) {echo ' selected';}
echo '>'.$certi[$cwr].'</option>';
}

echo '</select>';

:D

whammy
06-25-2002, 03:25 AM
Hey Pootergeist... I didn't realize you were Okii on lissaexplains.com - LOL.



EZ Archive Ads Plugin for vBulletin Copyright 2006 Computer Help Forum