Javascript Issue -Not working in Firefox
-
Thank you for reading this post. I am new to Javascript and ASP.NET development so please bear with me. I have a page that renders fine in IE but the same functionality gives me error in Firefox. I have a form which has a bunch of check boxes and there is a a particular checkbox lets call it ABC, and clicking on it, it needs to uncheck the other boxes, and if other check box is clicked, it shud uncheck the the ABC checkbox. The checkbox are created dynamically through code in a table cell. My app works fine in IE but not in Firefox. I know there are a few keywords that is Microsoft proprietary, and is not all browser friendly, but i cannot figure out how to change it. Here is my code below. All help is appreciated. the error I get in Firefox and Safari when I click on any checkbox is ctrl.ParentElement has no properties. All help and code sample/corrections are appreciated. Please note: I am a systems support guy who has to maintain pages. function ValidateCheckedValues( ctrl , isChecked ) { // Purpose : This function is called when the user clicks on any checkbox in the equipment requirements table on the page // If the user clicks on the "ABC" checkbox it clears all the check boxes for that meeting, // but if the user checked any other checkbox, it removes the check from the "ABC" checkbox try { if( ctrl.parentElement.attributes("SubCode").value == "NONE" ) { if( isChecked ) { for( counter = 3 ; counter < ctrl.parentElement.parentElement.parentElement.children.length ; counter++ ) { ctrl.parentElement.parentElement.parentElement.children( counter ).children( 0 ).children( 0 ).checked = false; } ctrl.checked = true; } } else { if( isChecked ) { for( counter = 3 ; counter < ctrl.parentElement.parentElement.parentElement.children.length ; counter++ ) { if( ctrl.parentElement.parentElement.parentElement.children( counter ).children( 0 ).attributes("SubCode").value == "NONE" ) { ctrl.parentElement.parentElement.parentElement.children( counter ).children( 0 ).children( 0 ).checked = false; } } } } }
-
Thank you for reading this post. I am new to Javascript and ASP.NET development so please bear with me. I have a page that renders fine in IE but the same functionality gives me error in Firefox. I have a form which has a bunch of check boxes and there is a a particular checkbox lets call it ABC, and clicking on it, it needs to uncheck the other boxes, and if other check box is clicked, it shud uncheck the the ABC checkbox. The checkbox are created dynamically through code in a table cell. My app works fine in IE but not in Firefox. I know there are a few keywords that is Microsoft proprietary, and is not all browser friendly, but i cannot figure out how to change it. Here is my code below. All help is appreciated. the error I get in Firefox and Safari when I click on any checkbox is ctrl.ParentElement has no properties. All help and code sample/corrections are appreciated. Please note: I am a systems support guy who has to maintain pages. function ValidateCheckedValues( ctrl , isChecked ) { // Purpose : This function is called when the user clicks on any checkbox in the equipment requirements table on the page // If the user clicks on the "ABC" checkbox it clears all the check boxes for that meeting, // but if the user checked any other checkbox, it removes the check from the "ABC" checkbox try { if( ctrl.parentElement.attributes("SubCode").value == "NONE" ) { if( isChecked ) { for( counter = 3 ; counter < ctrl.parentElement.parentElement.parentElement.children.length ; counter++ ) { ctrl.parentElement.parentElement.parentElement.children( counter ).children( 0 ).children( 0 ).checked = false; } ctrl.checked = true; } } else { if( isChecked ) { for( counter = 3 ; counter < ctrl.parentElement.parentElement.parentElement.children.length ; counter++ ) { if( ctrl.parentElement.parentElement.parentElement.children( counter ).children( 0 ).attributes("SubCode").value == "NONE" ) { ctrl.parentElement.parentElement.parentElement.children( counter ).children( 0 ).children( 0 ).checked = false; } } } } }
Let me guess... You are calling the function with the name of the element as first parameter instead of an actual reference to the element? Internet Explorer adds references to the elements in the page as members of the document object. This makes it easy to access the elements, but it's non-standard so it won't work in any other browser. Use the document.getElementById method to get a reference to the element.
Despite everything, the person most likely to be fooling you next is yourself.