function fails on second use?

Collapse
This topic is closed.
X
X
 
  • Time
  • Show
Clear All
new posts
  • Mark Anderson

    function fails on second use?

    I have this called by the onclick handler on a radio button group:

    function loadContacts(my Form){
    myForm.Contact. options.length= 0;
    var gpList = getSelectedRadi oValue(myForm.G roup_Name);
    var useList = new Array();
    useList = makeArray(gpLis t);
    //alert(useList[0][0]);
    if (useList !== '') {
    var x = useList.length;
    for (x = 0; useList[x]; x++) {
    myForm.Contact. options[x] = new Option(useList[x][0],
    useList[x][1],false,false);
    }
    }
    }

    I runs fine on first use and a drop-down is list is filled with names
    and their email address as a value. When I click a second radio button
    (even the currently selected one) , the script fails at this line:
    useList = makeArray(gpLis t); - saying 'function expected'. Why it worked
    first time round. FWIW, there are no global vars in play.

    I've tried setting useList = null at before quitting the function but it
    should be destroyed as it goes out of scope when the function finishes.

    Any ideas?

    Regards

    Mark


  • Lee

    #2
    Re: function fails on second use?

    Mark Anderson said:[color=blue]
    >
    >I have this called by the onclick handler on a radio button group:
    >
    >function loadContacts(my Form){
    >myForm.Contact .options.length = 0;
    >var gpList = getSelectedRadi oValue(myForm.G roup_Name);
    >var useList = new Array();
    >useList = makeArray(gpLis t);
    >//alert(useList[0][0]);
    >if (useList !== '') {
    > var x = useList.length;
    > for (x = 0; useList[x]; x++) {
    > myForm.Contact. options[x] = new Option(useList[x][0],
    >useList[x][1],false,false);
    > }
    > }
    >}
    >
    >I runs fine on first use and a drop-down is list is filled with names
    >and their email address as a value. When I click a second radio button
    >(even the currently selected one) , the script fails at this line:
    >useList = makeArray(gpLis t); - saying 'function expected'. Why it worked
    >first time round. FWIW, there are no global vars in play.[/color]


    It sounds as if you're assigning some value to a variable
    named "makeArray" that's clobbering the use of that name
    as a function. My first guess would be that you're doing
    that within the makeArray function, itself.

    Also note that it's redundant to assign a new Array to
    useList and then immediately replace that new Array with
    a different one. Use:

    var useList = makeArray(gpLis t);

    Comment

    • Mark Anderson

      #3
      Re: function fails on second use?

      >>>My first guess would be that you're doing
      that within the makeArray function, itself.<<<

      bingo!

      Thanks.

      Mark



      Comment

      Working...