Web Analytics Made Easy -
StatCounter Select form field woe - CodingForum

Announcement

Collapse
No announcement yet.

Select form field woe

Collapse
X
 
  • Filter
  • Time
  • Show
Clear All
new 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
    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.

    Comment


    • #3
      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
      Scripting | JavaScripts | PerlScripts | Python Scripts | Articles | My Journal

      Comment


      • #4
        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.

        Comment


        • #5
          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. ;)

          Comment

          Working...
          X