Home     |     .Net Programming    |     cSharp Home    |     Sql Server Home    |     Javascript / Client Side Development     |     Ajax Programming

Ruby on Rails Development     |     Perl Programming     |     C Programming Language     |     C++ Programming     |     IT Jobs

Python Programming Language     |     Laptop Suggestions?    |     TCL Scripting     |     Fortran Programming     |     Scheme Programming Language

Cervo Technologies
The Right Source to Outsource

MS Dynamics CRM 3.0

Javascript / Client Side Development

Set checkbox status - works in IE but not FF

At the top of a page I'm displaying a check box thus:

<input type='checkbox' name='ckbx1' onClick='saveStatus("ckbx1");'>ABC

I then execute the following to set the check box to whatever it was
the last time it was changed:

<script type='text/javascript'>
document.getElementById('ckbx1').checked = getCookie('ckbx1');

This seems to work ok in IE6 but in Firefox a "...has no properties"
error is generated when the script executes. The same error is
generated when I click on the check box.

What I'm doing wrong ?


What is wrong is simply that you use getElementById(), but didn't assign an
id to the checkbox.
You only named it. Names are for formelements (name/value-pairs) so the
receiving script can use them.
ids are for JS.

Solution: add the id to the box.

The reason IE does it 'right' is because IE does it wrong, and confuses name
with id.

Erwin Moller

On Wed, 16 May 2007 18:13:38 +0200, Erwin Moller

Thanks, Erwin - you're absolutely correct. It works now.
Add to del.icio.us | Digg this | Stumble it | Powered by Megasolutions Inc