Solved

JavaScript  document.getElementById not working in firefox

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

Free Tool: Port Scanner

Check which ports are open to the outside world. Helps make sure that your firewall rules are working as intended.

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.

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
html input 8 42
what is the best Integrated development environment 2 20
ASP exit 10 18
Help with Javascript to round decimal points to 2 13 15
Nothing in an HTTP request can be trusted, including HTTP headers and form data.  A form token is a tool that can be used to guard against request forgeries (CSRF).  This article shows an improved approach to form tokens, making it more difficult to…
Boost your ability to deliver ambitious and competitive web apps by choosing the right JavaScript framework to best suit your project’s needs.
In this tutorial viewers will learn how to position overlapping items using z-index in CSS. They will also learn the restrictions on the z-index property.  Create a new HTML document with an internal stylesheet.: Create a div in CSS and name it Red.…
In this tutorial viewers will learn how to embed videos in a webpage using HTML5. Ensure your DOCTYPE declaration is set to HTML5: "<!DOCTYPE html>": Use the <video> tag to insert a video. Define the src as the URL of your video; this is similar to …

860 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