Results 1 to 2 of 2

Thread: Javascript Auto Drop Down

  1. #1
    Join Date
    Aug 2005
    Posts
    14
    Thanks
    1
    Thanked 0 Times in 0 Posts

    Default Javascript Auto Drop Down

    Hi all

    Perhaps someone here can help. I'm using this script in a form:

    Code:
    <HEAD>
    
    <SCRIPT LANGUAGE="JavaScript">
    <!-- Begin
    team = new Array(
    new Array(
    new Array("Saku Koivu", 39482304),
    new Array("Martin Rucinsky", 34802389),
    new Array("Jeff Hackett", 39823498),
    new Array("Sheldon Sourray", 87587343),
    new Array("Richard Zednik", 68798735),
    ),
    new Array(
    new Array("Mario Lemieux", 23840238),
    new Array("Jaromir Jagr", 92390484),
    new Array("Robert Lang", 29048203),
    new Array("Alexei Kovalev", 94098230),
    new Array("Jean-Sebastien Aubin", 39234923),
    ),
    null,
    new Array(
    new Array("Alexei Yashin", 20394802),
    new Array("Daniel Alfredson", 34982039),
    new Array("Marian Hossa", 92348902),
    new Array("Patrick Lalime", 98203894),
    new Array("Radek Bonk", 98234902)
    )
    );
    function fillSelectFromArray(selectCtrl, itemArray, goodPrompt, badPrompt, defaultItem) {
    var i, j;
    var prompt;
    // empty existing items
    for (i = selectCtrl.options.length; i >= 0; i--) {
    selectCtrl.options[i] = null; 
    }
    prompt = (itemArray != null) ? goodPrompt : badPrompt;
    if (prompt == null) {
    j = 0;
    }
    else {
    selectCtrl.options[0] = new Option(prompt);
    j = 1;
    }
    if (itemArray != null) {
    // add new items
    for (i = 0; i < itemArray.length; i++) {
    selectCtrl.options[j] = new Option(itemArray[i][0]);
    if (itemArray[i][1] != null) {
    selectCtrl.options[j].value = itemArray[i][1]; 
    }
    j++;
    }
    // select first item (prompt) for sub list
    selectCtrl.options[0].selected = true;
       }
    }
    //  End -->
    </script>
    
    </HEAD>
    
    <BODY>
    
    <FORM NAME="main">
    <SELECT NAME="Make" onChange="fillSelectFromArray(this.form.Team, ((this.selectedIndex == -1) ? null : team[this.selectedIndex-1]));">
    <OPTION VALUE="-1">Select Team
    <OPTION VALUE=1>Montreal Canadiens
    <OPTION VALUE=2>Pittsburg Penguins
    <OPTION VALUE=3>Toronto Maple Leafs
    <OPTION VALUE=4>Ottawa Senators
    </SELECT>
    <BR>
    <SELECT NAME="Team" SIZE="5">
    <OPTION>                                  </OPTION>
    <OPTION>                                  </OPTION>
    <OPTION>                                  </OPTION>
    <OPTION>                                  </OPTION>
    <OPTION>                                  </OPTION>
    </SELECT>
    </FORM>
    </BODY>
    Source

    ... and it's working just fine except for one thing: if I select "Montreal Canadiens" and then "Saku Koivu" the email that I get with all the results shows the player as "39482304" which is the number associated with that player, ie

    Code:
    new Array("Saku Koivu", 39482304),
    I need the players name to come thru in the email, not the number. I tried putting the players name in " and ' but it didn't work, it seems to require numbers as opposed to letters. Can anyone help?

    Thanks

  2. #2
    Join Date
    Feb 2007
    Location
    England
    Posts
    254
    Thanks
    0
    Thanked 5 Times in 5 Posts

    Default

    Code:
    <html>
    <HEAD>
    
    <SCRIPT LANGUAGE="JavaScript">
    <!-- Begin
    team = new Array(
    new Array(
    	new Array("Saku Koivu", 39482304),
    	new Array("Martin Rucinsky", 34802389),
    	new Array("Jeff Hackett", 39823498),
    	new Array("Sheldon Sourray", 87587343),
    	new Array("Richard Zednik", 68798735)
    	),
    new Array(
    	new Array("Mario Lemieux", 23840238),
    	new Array("Jaromir Jagr", 92390484),
    	new Array("Robert Lang", 29048203),
    	new Array("Alexei Kovalev", 94098230),
    	new Array("Jean-Sebastien Aubin", 39234923)
    	),
    new Array(
    	new Array("Alexei Yashin", 20394802),
    	new Array("Daniel Alfredson", 34982039),
    	new Array("Marian Hossa", 92348902),
    	new Array("Patrick Lalime", 98203894),
    	new Array("Radek Bonk", 98234902)
    	)
    );
    
    function fillSelectFromArray (selectCtrl, itemArray, goodPrompt, badPrompt, defaultItem) {
    var i, j;
    var prompt;
    // empty existing items
    for (i = selectCtrl.options.length; i >= 0; i--) {
    selectCtrl.options[i] = null; 
    }
    prompt = (itemArray != null) ? goodPrompt : badPrompt;
    if (prompt == null) {
    j = 0;
    }
    else {
    selectCtrl.options[0] = new Option(prompt);
    j = 1;
    }
    if (itemArray != null) {
    // add new items
    for (i = 0; i < itemArray.length; i++) {
    selectCtrl.options[j] = new Option(itemArray[i][0]);
    if (itemArray[i][1] != null) {
    //selectCtrl.options[j].value = itemArray[i][1]; 
    }
    j++;
    }
    // select first item (prompt) for sub list
    selectCtrl.options[0].selected = true;
       }
    }
    //  End -->
    </script>
    
    </HEAD>
    
    <BODY>
    
    <FORM NAME="main">
    <SELECT NAME="Make" onChange="fillSelectFromArray (this.form.Team, ((this.selectedIndex === 0) ? null : team[this.selectedIndex-1]))">
    <OPTION Selected>Select Team
    <OPTION>Montreal Canadiens
    <OPTION>Pittsburg Penguins
    <OPTION>Toronto Maple Leafs
    <OPTION>Ottawa Senators
    </SELECT>
    <BR>
    <SELECT NAME="Team" SIZE="5">
    <OPTION>                                  </OPTION>
    <OPTION>                                  </OPTION>
    <OPTION>                                  </OPTION>
    <OPTION>                                  </OPTION>
    <OPTION>                                  </OPTION>
    </SELECT>
    </FORM>
    </BODY>
    </html>
    Last edited by Bob90; 05-19-2007 at 06:31 AM.

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
  •