• Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 536
  • Last Modified:

JavaScript document.getElementById not working in firefox

I have a javascript function that turns some checkboxes on and off depending on a main checkbox.  My code is in Classic ASP.

The code works fine in IE, but in FireFox, it recognizes the checkbox's id from which the Javascript function originated, but not other checkbox ids

Here is the code:

function Daypart1(){
    if (document.getElementById("OVNcheckbox").checked)
    {
        alert('In Daypart1 function - OVNcheckbox.checked ');   <-- It gets this far
        document.getElementById("H00checkbox").checked=true;
        alert('In Daypart1 function - H00checkbox.checked ');  <-- But not this far

    }

}

Here is the HTML code:

<table width="90%" align="center" ID="Table12">
                                    <input type=checkbox onclick="Daypart1()" name=daypart value=OVN id=OVNcheckbox <%=iIf(0<instr(daypart,"OVN"),"checked","")%> > <b>OVN</b>
                                    <tr><td class="blackMain10px">
                                    <input type=checkbox  onclick="OVNHours()" name=hours value=H00 id=H00Checkbox <%=iIf(0<instr(hours,"H00"),"checked","")%> >H00
.
0
dteshome
Asked:
dteshome
  • 3
  • 2
1 Solution
 
Gurvinder Pal SinghCommented:
what does it say when you put your values in double quotes?

<input type="checkbox" onclick="Daypart1()" name="daypart" value="OVN" id="OVNcheckbox" <%=iIf(0<instr(daypart,"OVN"),"checked","")%> > <b>OVN</b>
                                    <tr><td class="blackMain10px">
                                    <input type="checkbox"  onclick="OVNHours()" name="hours" value="H00" id="H00Checkbox" <%=iIf(0<instr(hours,"H00"),"checked","")%> >H00
.
0
 
dteshomeAuthor Commented:
No difference.
0
 
Gurvinder Pal SinghCommented:
what html is rendered at the run-time when you see on the browser? please check if the id that you have used is correct.

Also please replace the second line in if condition to

document.getElementById("H00checkbox").setAttribute("checked", true);
0
 
dteshomeAuthor Commented:
Actually the Problem ended up being because I was using an upper case 'C' for the id in the HTML code --> id=H00Checkbox , while using lower case 'c' in the Javascript code -- H00checkbox.checked.  This was an important lesson to me about Firefox browser being case sensitive.  IE did not care.
0
 
dteshomeAuthor Commented:
Settled on a different approach.
0

Featured Post

Free Tool: SSL Checker

Scans your site and returns information about your SSL implementation and certificate. Helpful for debugging and validating your SSL configuration.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

  • 3
  • 2
Tackle projects and never again get stuck behind a technical roadblock.
Join Now