Solved

JavaScript  document.getElementById not working in firefox

Posted on 2011-02-23
5
522 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

Enabling OSINT in Activity Based Intelligence

Activity based intelligence (ABI) requires access to all available sources of data. Recorded Future allows analysts to observe structured data on the open, deep, and dark web.

Join & Write a Comment

Suggested Solutions

Having worked on larger scale sites, we found out that you are bound to look at more scalable solutions to integrating widgets, code snippets or complete applications and mesh them into functional sites, in any given composition. To share some of…
This demonstration started out as a follow up to some recently posted questions on the subject of logging in: http://www.experts-exchange.com/Programming/Languages/Scripting/JavaScript/Q_28634665.html and http://www.experts-exchange.com/Programming/…
In this tutorial viewers will learn how to style elements, such a divs, with a "drop shadow" effect using the CSS box-shadow property Start with a normal styled element, such as a div.: In the element's style, type the box shadow property: "box-shad…
The viewer will learn the benefit of using external CSS files and the relationship between class and ID selectors. Create your external css file by saving it as style.css then set up your style tags: (CODE) Reference the nav tag and set your prop…

757 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

Need Help in Real-Time?

Connect with top rated Experts

23 Experts available now in Live!

Get 1:1 Help Now