Hello and welcome to our community! Is this your first visit?
Register
Enjoy an ad free experience by logging in. Not a member yet? Register.
Results 1 to 5 of 5
  1. #1
    Regular Coder
    Join Date
    May 2002
    Location
    London, England
    Posts
    369
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Select form field woe

    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
    Jeewhizz - MySQL Moderator
    http://www.sitehq.co.uk
    PHP and MySQL Hosting

  • #2
    Senior Coder joh6nn's Avatar
    Join Date
    Jun 2002
    Location
    72° W. 48' 57" , 41° N. 32' 04"
    Posts
    1,887
    Thanks
    0
    Thanked 1 Time in 1 Post
    i think it's

    document.form.select.options[phpVariable].selected = true;
    bluemood | devedge | devmo | MS Dev Library | WebMonkey | the Guide

    i am a loser geek, crazy with an evil streak,
    yes i do believe there is a violent thing inside of me.

  • #3
    Regular Coder
    Join Date
    Jun 2002
    Location
    Mumbai, India
    Posts
    218
    Thanks
    0
    Thanked 0 Times in 0 Posts
    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

  • #4
    Regular Coder
    Join Date
    Jun 2002
    Location
    UK
    Posts
    577
    Thanks
    0
    Thanked 0 Times in 0 Posts
    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>';

    Ökii - formerly pootergeist
    teckis - take your time and it'll save you time.

  • #5
    Senior Coder
    Join Date
    Jun 2002
    Location
    41° 8' 52" N -95° 53' 31" W
    Posts
    3,660
    Thanks
    0
    Thanked 0 Times in 0 Posts
    Hey Pootergeist... I didn't realize you were Okii on lissaexplains.com - LOL.
    Former ASP Forum Moderator - I'm back!

    If you can teach yourself how to learn, you can learn anything. ;)


  •  

    Posting Permissions

    • You may not post new threads
    • You may not post replies
    • You may not post attachments
    • You may not edit your posts
    •