By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
455,774 Members | 1,380 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 455,774 IT Pros & Developers. It's quick & easy.

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

P: n/a

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
Jul 23 '05 #1
Share this Question
Share on Google+
5 Replies


P: n/a
> // 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
Jul 23 '05 #2

P: n/a
Deniz Adrian wrote:
// 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

Luvely Juvely... Thanks for that!

randelld
Jul 23 '05 #3

P: n/a
Randell D. wrote:
Deniz Adrian wrote:
// 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

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>

Jul 23 '05 #4

P: n/a
Oops, correction:

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

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

Jul 23 '05 #5

P: n/a
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
}

Jul 23 '05 #6

This discussion thread is closed

Replies have been disabled for this discussion.