Click to See Complete Forum and Search --> : Javascript: Checkbox readonly problem


Dr. Butterboy
12-19-2003, 11:46 AM
On a webpage, I have a checkbox called "chkN___EFUN" that's sometimes readonly and I wanted to interrogate its value when the page is submitted.

When the check box is read only I found that referencing this object like so "document.all.chkN___EFUN(0).value" would give me a true/false.

But, when this value was not read only I would need to reference it like this "document.all.chkN___EFUN.value" or I would get the javascript error "Object does not support this method or property".

Does anyone know the best way to handle this situation I can get the value of the check box when its readonly and not readonly?

Thanks!

:confused:

batfink
12-19-2003, 01:56 PM
The property of the check box you should be looking at is checked not value. This will return true or false.

olerag
12-19-2003, 02:01 PM
Here's a little code that might offer you some ideas....


<html>
<head>
<script type="text/javascript">
function doDemo(form) {
var cbObj = form.cbObj;

if (cbObj.checked)
alert("Value is " + cbObj.value);
else
alert("No value will be submitted.");

if (cbObj.disabled)
cbObj.disabled = false;
else
cbObj.disabled = true;
}
</script>
</head>
<body>
<center>
<b>Read-only Checkbox Demo</b>
<form>
<input type="checkbox" name="cbObj" value="Y" disabled>
<p>
<input type="button" value="Execute" onClick="doDemo(this.form)">
</form>
<hr>
</center>
</body>
</html>