SitePoint Sponsor

User Tag List

Results 1 to 6 of 6
  1. #1
    SitePoint Zealot Da Mouse's Avatar
    Join Date
    Aug 2002
    Posts
    111
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    Talking the larger the script the better the problems


    <HTML>
    <HEAD>
    <TITLE>LANGUAGE</TITLE>

    <SCRIPT language="javascript">
    <!--hide from old grannies
    var volks = new Array();
    volks[0] = "beatle";
    volks[1] = "sharan";
    volks[2] = "passat";

    var volks2 = new Array();
    volks2[0] = "golf";
    volks2[1] = "sharan";
    volks2[2] = "passat";
    volks2[3] = "beatle";

    function add_options()
    {
    var dropdownchange = window.document.boogle.google;
    for(var x=0;x <dropdownchange.length ; x++)
    {
    the_select.options[x].text = volks2[x];
    }
    for(;volks2.length <dropdownchange.length
    {
    var new_option = new Option;
    var new_option.text = good_url;
    var dropdownchange.options[dropdownchange.length]= new_option;
    }
    }
    //let them put there glasses on -->
    </SCRIPT>

    </HEAD>
    <BODY>
    <FORM name="boogle">
    <SELECT name="google">

    <SCRIPT language="javascript">
    <!--hide from old grannies
    for(var x = 0; x <volks.length; x++)
    {
    document.writeln("<OPTION value='" + volks[x] + "'>" + volks[x] + "</OPTION>");
    }
    //let them put there glasses on -->
    </SCRIPT>

    </SELECT>

    <INPUT type="submit" onClick="add_options();return false;">
    </FORM>
    </BODY>
    </HTML>


    the select box comes out blank!!
    I am DaMouse
    Nobody can beat me so long as I'm stubborn -DaMouse
    Squeak

  2. #2
    SitePoint Evangelist pip's Avatar
    Join Date
    Jun 2001
    Location
    Cape Town, South Africa
    Posts
    548
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    The problem lies in your second FOR loop in the add_options() function. I'm not sure why you're using a for loop in this case, so I've changed it to a WHILE loop.

    Below are the changes:

    Code:
    while(volks2.length <dropdownchange.length)
    {
      var new_option = new Option;
      new_option.text = good_url;
      dropdownchange.options[dropdownchange.length]= new_option;
    }

    You've first of all redeclared two new variables from an Option object that's already been delcared. I've removed the VAR statements from the new_option.text and dropdownchange.options properties.
    - Pip
    ---------------------------------------------------------------------------------
    Nothing takes the taste out of peanut butter quite like unrequited love.

  3. #3
    SitePoint Zealot Da Mouse's Avatar
    Join Date
    Aug 2002
    Posts
    111
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    new function
    function add_options()
    {
    var dropdownchange = window.document.boogle.google;
    for(var i=0;i <dropdownchange.length ; i++)
    {
    the_select.options[x].text = volks2[i];
    }
    while(volks2.length <dropdownchange.length)
    {
    var new_option = new Option;
    new_option.text = volks2[dropdownchange.length];
    dropdownchange.options[dropdownchange.length]= new_option;
    }
    }


    but when I hit the submit button it submits the form and doesn't change the select box

    form tag


    <FORM onSubmit="add_options(); return false;" name="boogle">


    any ideas
    I am DaMouse
    Nobody can beat me so long as I'm stubborn -DaMouse
    Squeak

  4. #4
    SitePoint Zealot Da Mouse's Avatar
    Join Date
    Aug 2002
    Posts
    111
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    ok that now work but the new option volks[3] isn't added as a new option any ideas?
    I am DaMouse
    Nobody can beat me so long as I'm stubborn -DaMouse
    Squeak

  5. #5
    SitePoint Zealot Da Mouse's Avatar
    Join Date
    Aug 2002
    Posts
    111
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    I figured it out

    the answer to life the universe and everything is 42

    oh and I had the while loop wrong

    dropdownchange.length <volks2.length
    instead of
    volks2.length <dropdownchange.length
    I am DaMouse
    Nobody can beat me so long as I'm stubborn -DaMouse
    Squeak

  6. #6
    SitePoint Evangelist pip's Avatar
    Join Date
    Jun 2001
    Location
    Cape Town, South Africa
    Posts
    548
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Great... glad you could sort it out
    - Pip
    ---------------------------------------------------------------------------------
    Nothing takes the taste out of peanut butter quite like unrequited love.


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
  •