472,958 Members | 2,583 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 472,958 software developers and data experts.

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


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
5 5593
> // 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
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
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
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
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 thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

2
by: Mark | last post by:
Hi - when I add (dynamically) a row to a table, which includes a checkbox, I want the value of the checkbox to be posted along with the other controls already on the form when the form is...
7
by: Tony Cooke | last post by:
Hi all. I'm not sure why I'm having problems with this but if I try to retrieve the value of a readonly text form I get back that the object is undefined. The reason the text is readonly is...
12
by: Randell D. | last post by:
Folks, I have a form called "ourTestForm". Its a test form - nothing special - it contains five input tags - they are named one, two, three, four and five. The input tags are of type...
3
by: JOSEPHINE ALVAREZ | last post by:
I have this code that I want to use to do a rollover. However, because the company I am doing it for is continually changing the text, I want to be able to use dynamic text to change the text on...
1
by: bobby1041 | last post by:
Hi All! I am trying to make several fields in a HTML form validated, but only when a dynamic checkbox is selected. I am not sure how to do this. Here is a snippet of the dynamic checkbox...
0
by: andrei | last post by:
Hi Group, I have a checkbox column in a web datagrid which is related to a "Product in stock" property. The grid is in view mode, so the user can't (and shouldn't) change anything in the grid....
3
by: James Wong | last post by:
Dear Sir, I want to create some dynamic checkbox controls into the table. How can I get these controls after the form is submitted. ----------------------------------------------------- e.g....
3
Nikky
by: Nikky | last post by:
I m using C#.net i m using a placeholder which contains dynamic table and dynamic checkbox .i want to position check box after each row.but i want to place it after table.not within the table. ...
8
by: TingYan | last post by:
Hello, I am a beginner of writing vbscript and I am now facing a question, my coding as follow <% dim ID(5) dim value(5) dim count = 5 dim i = 0 while i<count response.write("<form>")...
2
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 4 Oct 2023 starting at 18:00 UK time (6PM UTC+1) and finishing at about 19:15 (7.15PM) The start time is equivalent to 19:00 (7PM) in Central...
0
tracyyun
by: tracyyun | last post by:
Hello everyone, I have a question and would like some advice on network connectivity. I have one computer connected to my router via WiFi, but I have two other computers that I want to be able to...
2
by: giovanniandrean | last post by:
The energy model is structured as follows and uses excel sheets to give input data: 1-Utility.py contains all the functions needed to calculate the variables and other minor things (mentions...
4
NeoPa
by: NeoPa | last post by:
Hello everyone. I find myself stuck trying to find the VBA way to get Access to create a PDF of the currently-selected (and open) object (Form or Report). I know it can be done by selecting :...
3
NeoPa
by: NeoPa | last post by:
Introduction For this article I'll be using a very simple database which has Form (clsForm) & Report (clsReport) classes that simply handle making the calling Form invisible until the Form, or all...
0
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 1 Nov 2023 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM) Please note that the UK and Europe revert to winter time on...
0
NeoPa
by: NeoPa | last post by:
Introduction For this article I'll be focusing on the Report (clsReport) class. This simply handles making the calling Form invisible until all of the Reports opened by it have been closed, when it...
0
isladogs
by: isladogs | last post by:
The next online meeting of the Access Europe User Group will be on Wednesday 6 Dec 2023 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). In this month's session, Mike...
2
by: GKJR | last post by:
Does anyone have a recommendation to build a standalone application to replace an Access database? I have my bookkeeping software I developed in Access that I would like to make available to other...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.