Results 1 to 4 of 4

Thread: how to use a script twice independently?

  1. #1
    Join Date
    Dec 2008

    how to use a script twice independently?

    Hi everyone,
    I'm trying to use a javascript to fill 3 select boxes. Pretty simple stuff really, first select the top one and select an option then the second select box will fill with options applicable to it, and so on for the third. Problem is that I am already using the script in my toolbar to do exactly the same. I cant figure out how to use the same script again on the same page. Because for it to work the form needs to be named drop_list, but then i have two forms on one page called drop_list and it doesn't like that. How can i get around this?
    i have included the start of the function that fills the select boxes below:

    function fillCategory(){
    // this function is used to fill the category list on load
    addOption(document.drop_list.AllRegions, "Auckland", "Auckland", "");
    addOption(document.drop_list.AllRegions, "BayOfPlenty", "Bay of Plenty", "");
    addOption(document.drop_list.AllRegions, "Otago", "Otago", "");

    function SelectAllCities(){
    // ON selection of category this function will fill the cities box

    Thanks a lot for the help!

  2. #2
    Join Date
    Dec 2005
    Aside from the issue that you are using the same name on two different forms, the best way to do it is to give your select boxes unique ids and then use:

    I've switched careers...
    I'm NO LONGER a scientist,
    but now a web developer...

  3. #3
    Join Date
    May 2007
    You could expand the function to take the name of the form as a parameter:

    function fillCategory(formID){
    // this function is used to fill the category list on load
    addOption(document[formID].AllRegions, "Auckland", "Auckland", "");
    addOption(document[formID].AllRegions, "BayOfPlenty", "Bay of Plenty", "");
    addOption(document[formID].AllRegions, "Otago", "Otago", "");

  4. #4
    Join Date
    Dec 2002
    Pleasanton, CA
    Take a look at this.

    May give you some ideas.

Thread Information

Users Browsing this Thread

There are currently 1 users browsing this thread. (0 members and 1 guests)

Posting Permissions

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