SitePoint Sponsor

User Tag List

Results 1 to 7 of 7
  1. #1
    SitePoint Enthusiast
    Join Date
    Jan 2005
    Location
    Nigeria
    Posts
    51
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    Selected Index Problem

    I need to be able to dynamically set the selected value in a drop down list...
    I have tried the code that follows but nothing seems to happen

    <script language="javascript">

    function getInitial()
    {
    document.form1.select1.selectedIndex == 2

    }
    </script>

    <body Onload= "getInitial()">

    <select name="select1">
    <option value="1">red</option>
    <option value = "2"> green </option>
    <option value = "3> blue </option>
    <option value = "4> yellow<option>
    </body>
    </html>

    Please Heeeelppp!!!!!!!!!

  2. #2
    SitePoint Wizard chris_fuel's Avatar
    Join Date
    May 2006
    Location
    Ventura, CA
    Posts
    2,750
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    document.form1.select1.selectedIndex == 2 <-- any reason you're using 2 = signs there?

  3. #3
    SitePoint Enthusiast
    Join Date
    Jan 2005
    Location
    Nigeria
    Posts
    51
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Quote Originally Posted by chris_fuel
    document.form1.select1.selectedIndex == 2 <-- any reason you're using 2 = signs there?
    Tried it without the '==' and still gat the same results... what am I doing wrong???
    Last edited by Lashman; Jun 6, 2006 at 07:31. Reason: Mistype

  4. #4
    SitePoint Wizard chris_fuel's Avatar
    Join Date
    May 2006
    Location
    Ventura, CA
    Posts
    2,750
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    document.form1.select1.selectedIndex

    Where's form1?

  5. #5
    SitePoint Enthusiast
    Join Date
    Jan 2005
    Location
    Nigeria
    Posts
    51
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Quote Originally Posted by chris_fuel
    document.form1.select1.selectedIndex

    Where's form1?
    <script language="javascript">

    function getInitial()
    {
    document.form1.select1.selectedIndex == 2

    }
    </script>

    <body Onload= "getInitial()">
    <form name="form1" action="#" method = "post">
    <select name="select1">
    <option value="1">red</option>
    <option value = "2"> green </option>
    <option value = "3> blue </option>
    <option value = "4> yellow<option>
    </form>
    </body>
    </html>

  6. #6
    SitePoint Wizard chris_fuel's Avatar
    Join Date
    May 2006
    Location
    Ventura, CA
    Posts
    2,750
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    You still haven't gotten rid of the double equal signs though

  7. #7
    CSS & JS/DOM Adept bronze trophy
    Join Date
    Mar 2005
    Location
    USA
    Posts
    5,482
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    I suggest you try the following instead:
    Code:
    document.form1.select1.options[2].selected=true;
    We miss you, Dan Schulz.
    Learn CSS. | X/HTML Validator | CSS validator
    Dynamic Site Solutions
    Code for Firefox, Chrome, Safari, & Opera, then add fixes for IE, not vice versa.


Bookmarks

Posting Permissions

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