Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Mike Lewis on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Javascript errors with IE/Firefox, all ok with Chrome 2

Status
Not open for further replies.

arunrr

Programmer
Oct 2, 2009
103
US
Hello,

I have the following page...


Code may be viewed via right-click, 'view source'

As you choose the quarter-final winners, the semi-finalists are populated and the check boxes are enabled.

The intended workings of the page can be seen by visiting the URL above using GOOGLE CHROME.

However, with both IE and Firefox, I am getting errors with the javascript code.

All input is appreciated...

Thanks,
Arun
 
Providing the full error message and code would be helpful. we shouldn't need to visit the site to find out what your problem is. having this information as part of the post will help us help you.

each browser interprets javascript a little differently. so I'm guessing this the were the problem is. using a javascript library like jquery abstracts the idiosyncrasies of the browsers so you have 1 common api to work with. that may be an option to solve your problem.

another problem could be malformed html. for example you are missing a TR tag in a table, or an opening tag is missing a closing tag.

but without the details of the error and offending JS it's pure speculation.

Jason Meckley
Programmer

faq855-7190
faq732-7259
 
Thanks for your reply...

Message: 'document.getElementById(...)' is null or not an object
Line: 33

This refers to the line in following function

function disable(X)
{
for(var i=1;i<5;i++)
document.getElementById(X+i).disabled=true;
}


Message: 'A1' is undefined
Line: 48

This refers to the following function...

function assignSTeam(obj, Q)
{
oldtext=Q.substr(1,2);
switch (obj)
{
case A1: newtext="Australia"; q1text=newtext; break;
case A2: newtext="Pakistan"; q2text=newtext; break;
case A3: newtext="Sri Lanka"; q3text=newtext; break;
case A4: newtext="New Zealand"; q4text=newtext; break;
case B1: newtext="India"; q4text=newtext; break;
case B2: newtext="South Africa"; q3text=newtext; break;
case B3: newtext="West Indies"; q2text=newtext; break;
case B4: newtext="England"; q1text=newtext; break;
}
}

The 2 errors highlighted above are with both IE and Firefox.

Thanks
AR
 
getElementById expects the id of a control. id's are text, you are supplying a number. null is returned therefore a disabled field does not exist.
Code:
function disable(X)
{
   for(var i=1;i<5;i++)
   {
      var id = X+i;
      var element = document.getElementById(id.toString())
      element.disabled=true;
   }
}
a similar problem with your case statement. the browser does not know how to interpret A1, A2 etc, because these values are not defined.

Jason Meckley
Programmer

faq855-7190
faq732-7259
 
Thanks for your input Jason.

When i call the disable function, i use for example...

disable('Q');

I was under the impression that I am passing a text value to the id. By appending the i value, i am attempting to disable check boxes, Q1, Q2 Q3 and Q4.

I used your function instead, and get the fol error...

Message: 'null' is null or not an object
Line: 37

I also tried the following, get similar error

document.getElementById(X+i+'').disabled=true;

Thanks
AR
 
The issue is in your loop. While it works with the Q checkboxes because there are 4 of them. It doesn't work for the S checkboxes because there are only 2 of them.

If you add an alert to your for loop you'll see that it goes through the 4 Q checkboxes just fine. But then it goes through the S checkboxes but since there are only 2 of them the second your loop hits S3 it can't find an object with that id, and so returns Null.

Code:
for(var i=1;i<5;i++) {[red] alert('id = '+X+i+'');[/red] id = ''+X+i+''; document.getElementById(id).disabled=true; }

You'll need to modify your loop if you are checking for Q or for S.

Additionally I get an Obj is undefined here:

Code:
function doClick(Z, N)
      {
        if(obj.checked)
        {
          document.getElementById(N).innerText=newtext;
          document.getElementById(Z).disabled=true;
        }

Pretty straight forward since your function never defines the obj variable.

You need to go through your code slowly, and debug those errors. The Js errors are telling you what is wrong. you just need to use that info to correct them.




----------------------------------
Phil AKA Vacunita
----------------------------------
Ignorance is not necessarily Bliss, case in point:
Unknown has caused an Unknown Error on Unknown and must be shutdown to prevent damage to Unknown.

Behind the Web, Tips and Tricks for Web Development.
 
Thanks all for the input. I fixed the script to where it work in Chrome and IE. Still having issues with FF. Probably going to just let it be for now...

Thanks
AR
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top