JavaScript and client side scripting.
Moderator: General Moderators
myleow
Forum Contributor
Posts: 194 Joined: Mon Jun 21, 2004 7:05 pm
Location: California
Post
by myleow » Thu Nov 04, 2004 10:59 pm
I am getting this error on Internet Explorer 6.0
Code: Select all
Char: 3
Error: 'cb.checked' is null or not an object
Code: 0
Although I.E. is reporting a Javascript error, it works fine in highlighting the row that i just clicked on the checkbox. There are no Error warning when using Netscape or Firefox. Anyone know why?
Code: Select all
<SCRIPT LANGUAGE="JavaScript">
function getElement(id)
{
if(document.all)
return document.allїid];
else
return document.getElementById(id);
}
function highlight(num)
{
cb = getElement('cb'+num);
row_cb = getElement('row'+num);
if(cb.checked == true)
row_cb.style.backgroundColor = "lightblue";
else
row_cb.style.backgroundColor = "white";
}
</SCRIPT>
<tr id="row0"><td><input id="cb0" type="checkbox" name="deletelistї0]" value=66 onClick="highlight('0')"></input></td></tr>
<tr id="row1"><td><input id="cb1" type="checkbox" name="deletelistї1]" value=64 onClick="highlight('1')"></input></td></tr>
Thank you in advance.
Regards
Mian
Last edited by
myleow on Fri Nov 05, 2004 12:09 am, edited 1 time in total.
Weirdan
Moderator
Posts: 5978 Joined: Mon Nov 03, 2003 6:13 pm
Location: Odessa, Ukraine
Post
by Weirdan » Thu Nov 04, 2004 11:18 pm
It does work on IE 6.0.2900.2180 sp2. I would suggest to change:
Code: Select all
//.......
if(cb.checked == true)
//......
to
though
myleow
Forum Contributor
Posts: 194 Joined: Mon Jun 21, 2004 7:05 pm
Location: California
Post
by myleow » Thu Nov 04, 2004 11:25 pm
Thanks for your help, but I still get the same error after I changed to
Weirdan
Moderator
Posts: 5978 Joined: Mon Nov 03, 2003 6:13 pm
Location: Odessa, Ukraine
Post
by Weirdan » Fri Nov 05, 2004 12:52 am
place an alert s in highlight function. Seems like cb is indeed undefined.
phpScott
DevNet Resident
Posts: 1206 Joined: Wed Oct 09, 2002 6:51 pm
Location: Keele, U.K.
Post
by phpScott » Fri Nov 05, 2004 2:54 am
if sometime find that IE doesn't like to do the getElmentById() like you have done it, so i usually do.
Code: Select all
function highlight(num)
{
tCb='cb'+num ;
cb = getElement(tCb);
tRow='row'+nim;
row_cb = getElement(tRow);
if(cb.checked == true)
row_cb.style.backgroundColor = "lightblue";
else
row_cb.style.backgroundColor = "white";
}
The other big difference that I find when coding JS across the browsers is that in mozilla based browsers using a variable name the same as an element name or id is fine but under IE it doens't work.