Jump to content

clickListener not working in Explorer


wdallman

Recommended Posts

This clickListener works perfectly in Firefox, but not in Explorer. Any ideas as to why??  Note - using the core library for Core.addEventListener()

 

var numDriversLast = -1; // placeholder for the previous value of numDrivers

var driverForm =

{

    init: function() //when the form is loaded, this function runs

    {

        //assign name from html 'selDrivers' to variable 'drivers'

        var drivers = document.getElementById("selDrivers");

 

        //Use core library to add event listener

        Core.addEventListener(drivers, "change", driverForm.clickListener);

    },

    removeChildrenFromNode: function(node)

    {

while (node.hasChildNodes())

{

  x= node.removeChild(node.firstChild);

        //alert(x.nodeName);

}

    },

 

    clickListener: function() //the function that runs when the user clicks

    {

        //store the number of drivers selected into variable 'numDrivers''

        var numDrivers = document.getElementById("selDrivers").value;

        if(numDriversLast == -1){// if first time through...

            numDriversLast = numDrivers;

        }

        //remove elements in the table if currently printed to page

        //(if user already clicked a number of drivers, and is now doing it again)

        for(j=1; j <= numDriversLast; j++){

            driverTableId = "driverTable" + j;

            var tableToRemove = document.getElementById(driverTableId);

            // alert(tableToRemove.hasChildNodes() );

            driverForm.removeChildrenFromNode(tableToRemove);

        }

        //alert("NumDrivers" + numDrivers);

        //use for loop to display input fields within table

        for(i=1;i <= numDrivers; i++){

            id = "driverTable" + i;

            var tbl = document.getElementById(id);

            tbl.innerHTML="<thead id='thead'>Driver " + i + "</thead>\n\

                      <tr id='tr'>\n\

                        <td id='td'>First Name:</td>\n\

                        <td id='td'><input type='text' name='First Name " + i + "' class='required'/></td>\n\

                      </tr>\n\

                    ";

        }//end for loop

        numDriversLast = numDrivers;

    }//end clickListener()

};

 

Core.start(driverForm);

Link to comment
Share on other sites

I think the issue is with document.getElementById(). In FireFox, tbl will be [object HTMLTableElement] and with IE tbl will be [object].

 

var tbl = document.getElementById(id);

            alert(tbl);

            tbl.innerHTML="string";

Link to comment
Share on other sites

Solved it!

 

Apparently, IE does NOT allow .innerHTML when dealing with a table.  So, I simply changed them to divs with the correct ‘id’, and then put the table tags in the string that is to be printed when the clickListener is called.  Now it works!

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.