Solved

JavaScript  document.getElementById not working in firefox

Posted on 2011-02-23
5
530 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 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

Industry Leaders: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
Technology Resume 7 69
Html date format 9 20
Echo'd values in dropdowns 6 30
Boolean 13 24
Today, the web development industry is booming, and many people consider it to be their vocation. The question you may be asking yourself is – how do I become a web developer?
When crafting your “Why Us” page, there are a plethora of pitfalls to avoid. Follow these five tips, and you’ll be well on your way to creating an effective page.
In this tutorial viewers will learn how to position items using CSS's three positioning types Create a new HTML document with an internal stylesheet.: Create another div in CSS and name it Absolute : Type "position:absolute;" and "top:10px; left:50p…
The viewer will the learn the benefit of plain text editors and code an HTML5 based template for use in further tutorials.

726 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