Solved

JavaScript  document.getElementById not working in firefox

Posted on 2011-02-23
5
527 Views
Last Modified: 2012-05-11
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
Comment
Question by:dteshome
  • 3
  • 2
5 Comments
 
LVL 40

Expert Comment

by:gurvinder372
ID: 34962766
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
 

Accepted Solution

by:
dteshome earned 0 total points
ID: 34965226
No difference.
0
 
LVL 40

Expert Comment

by:gurvinder372
ID: 35006328
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
 

Author Comment

by:dteshome
ID: 35167235
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
 

Author Closing Comment

by:dteshome
ID: 35187386
Settled on a different approach.
0

Featured Post

PRTG Network Monitor: Intuitive Network Monitoring

Network Monitoring is essential to ensure that computer systems and network devices are running. Use PRTG to monitor LANs, servers, websites, applications and devices, bandwidth, virtual environments, remote systems, IoT, and many more. PRTG is easy to set up & use.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

This is a PowerShell web interface I use to manage some task as a network administrator. Clicking an action button on the left frame will display a form in the middle frame to input some data in textboxes, process this data in PowerShell and display…
Find out what you should include to make the best professional email signature for your organization.
The viewer will the learn the benefit of plain text editors and code an HTML5 based template for use in further tutorials.
HTML5 has deprecated a few of the older ways of showing media as well as offering up a new way to create games and animations. Audio, video, and canvas are just a few of the adjustments made between XHTML and HTML5. As we learned in our last micr…

810 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question