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 SkipVought on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

cross browser check box functionality

Status
Not open for further replies.

nicasa

Programmer
Feb 3, 2003
54
0
0
ES
HI Gurus,

I have created a simple function that enables a text field if a check box is ticked. (and vice versa)
Here is the code ...

<input name = "vm_box" type = "checkbox" onClick="enableField('vm_pin', 'vm_box')" />
<input name = "vm_pin" type = "text" maxlength = "5" disabled />

function enableField(text_id, vm_box_id)
{
var a = document.getElementById(vm_box_id);
var e = document.getElementById(text_id);
if (a.checked)
{
e.disabled=false;
e.focus();
}
else
{
e.disabled=true;
e.value = "";
}
}

It works fine in MS IE but not in firefox. I have tried changing it but I cannot get it to work in BOTH browsers.

Does anyone have any ideas ?

regards,

Steven Matthews
 
You haven't set the id attributes in your HTML.

[sub]Never be afraid to share your dreams with the world.
There's nothing the world loves more than the taste of really sweet dreams.
[/sub]

Webflo
 
IE allows sloppy coding, which this is an example of. If you're only going to use names, you need to use document.getElementsByName() and then refer to the first object in the array (even if there's only object with that name, it'll be in an array).

Lee
 
THanks guys, my problem is now solved !

Steven M
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top