dynamic readOnly for type=text works, but not for checkbox

R

Randell D.

Folks,

I have a few <INPUT TYPE=TEXT> tags that are readonly if a specific
field has no value... these work fine. However, I also have checkboxes
which I would like to have as readonly, but the same code doesn't work -
Can someone suggest a solution?

This is sample code extracted from my original code:

// Before other input tags determine if they are read only or not,
// they check input tag sp6 has a value
<input name="sp6" type="text" id="sp6" size="8" maxlength="24">

// This works - input tag f6 is read only unless sp6 has a value
<input name="f6" type="text" id="f6" size="10" maxlength="24"
onFocus="if(sp6.value){f6.readOnly=false} else {f6.readOnly=true}">

// This does not work (checkbox tick on & off is always permitted
// regardless if sp6 has a value or not...
<input name="mon6" type="checkbox" id="mon6" value="1"
onFocus="if(sp6.value){mon6.readOnly=false} else {mon6.readOnly=true}">


I have tried onFocus, onChange and onBlur.

I am working on an intranet application built 100% for Mozilla browsers
if browser dependancy proves to be a problem.

All help, via the newsgroup so all can learn is greatly appreciated...

thanks
randelld
 
D

Deniz Adrian

// This does not work (checkbox tick on & off is always permitted
// regardless if sp6 has a value or not...
<input name="mon6" type="checkbox" id="mon6" value="1"
onFocus="if(sp6.value){mon6.readOnly=false} else {mon6.readOnly=true}">
try

mon6.disabled=true;

instead of
mon6.readOnly=true;

worx fine in my Firefox

best regards
deniz adrian
 
R

RobB

Randell said:
Luvely Juvely... Thanks for that!

randelld

<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01//EN"
"http://www.w3.org/TR/html4/str­­­­ict.dtd">
<html>
<head>
<title>untitled</title>
<script type="text/javascript">

window.onload = function()
{
var f, el;
if (f = document.forms[0]
&& (el = f.elements.f6))
el.onfocus(); //keep it in sync
}

</script>
</head>
<body>
<form>
<input name="sp6" type="text" id="sp6" size="8" maxlength="24" />
<input name="f6" type="text" id="f6" size="10" maxlength="24"
onfocus="this.readOnly=!sp6.value" />
<input type="checkbox" onclick="this.checked=this.defaultChecked" />
<input type="checkbox" checked="checked"
onclick="this.checked=this.defaultChecked" />
</form>
</body>
</html>
 
R

RobB

Oops, correction:

onfocus="this.readOnly=/^\s*$/.test(sp6.value)" />

....as the entry '0' will cast to false with the former approach.
 
R

RobB

Monday and I'm tired already....

window.onload = function()
{
var f, el;
if ((f = document.forms[0])
&& (el = f.elements.f6))
el.onfocus(); //keep it in sync
}
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,770
Messages
2,569,584
Members
45,075
Latest member
MakersCBDBloodSupport

Latest Threads

Top