473,320 Members | 2,161 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,320 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 5606
> // 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>")...
0
by: DolphinDB | last post by:
The formulas of 101 quantitative trading alphas used by WorldQuant were presented in the paper 101 Formulaic Alphas. However, some formulas are complex, leading to challenges in calculation. Take...
0
by: DolphinDB | last post by:
Tired of spending countless mintues downsampling your data? Look no further! In this article, you’ll learn how to efficiently downsample 6.48 billion high-frequency records to 61 million...
0
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 6 Mar 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). In this month's session, we are pleased to welcome back...
0
by: Vimpel783 | last post by:
Hello! Guys, I found this code on the Internet, but I need to modify it a little. It works well, the problem is this: Data is sent from only one cell, in this case B5, but it is necessary that data...
1
by: PapaRatzi | last post by:
Hello, I am teaching myself MS Access forms design and Visual Basic. I've created a table to capture a list of Top 30 singles and forms to capture new entries. The final step is a form (unbound)...
0
by: CloudSolutions | last post by:
Introduction: For many beginners and individual users, requiring a credit card and email registration may pose a barrier when starting to use cloud servers. However, some cloud server providers now...
0
by: Defcon1945 | last post by:
I'm trying to learn Python using Pycharm but import shutil doesn't work
0
by: af34tf | last post by:
Hi Guys, I have a domain whose name is BytesLimited.com, and I want to sell it. Does anyone know about platforms that allow me to list my domain in auction for free. Thank you
0
by: Faith0G | last post by:
I am starting a new it consulting business and it's been a while since I setup a new website. Is wordpress still the best web based software for hosting a 5 page website? The webpages will be...

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.