473,804 Members | 2,673 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

Disabling fields based on a checkbox.

Hi,

There are lots of posts on this subject but after a couple of hours of
going though them I still can't get a number of fields to be disabled
when a checkbox is ticked. Basically I have a lot of Forecast and
Actual dates that can be entered, and next to each one an 'NA' checkbox
that I want to disable/grey-out both dates (and the JavaScript calendar
if possible). It also only has to work on Internet Explorer 6, as it
is for internal use only.

Any help greatly welcome as this is starting to drive me mad.

Code extract of form below.

Thanks,

Steve

<form name="lform" method="get" action="UpdateD B.asp">
[...]
<tr>
<td><b>Forecast 1:</b> <input type="text" name="Forecast1 " id="Date14"
size="10" maxlength="10" value="<%=ForeC ast1%>">
<img src="/images/icons/calendar.gif" id="Trig14" style="cursor:
pointer; border: 1px solid red;" title="Date selector"></td>

<td><b>Actual1: </b> <input type="text" name="Actual1" id="Date15"
size="10" maxlength="10" value="<%=Actua l1%>">
<img src="/images/icons/calendar.gif" id="Trig15" style="cursor:
pointer; border: 1px solid red;" title="Date selector">/</td>

<td><input type="checkbox" NAME="NA1" VALUE=1> N/A</td>
</tr>
[...]
</form>

Nov 9 '05 #1
6 3436
ML.Steve wrote:
There are lots of posts on this subject but after a couple of hours of
going though them I still can't get a number of fields to be disabled
when a checkbox is ticked.
What exactly have you not understood? What have you tried? What failed
with which error?
Basically I have a lot of Forecast and
Actual dates that can be entered, and next to each one an 'NA' checkbox
that I want to disable/grey-out both dates (and the JavaScript calendar
if possible).
Why, you just need to disable either both elements or their parent
`fieldset' element when the checkbox was clicked and is checked.
Any help greatly welcome as this is starting to drive me mad.
If I could *see* efforts on your part, I would gladly provide further help.
Code extract of form below.


There is not one line of JS/ECMAScript, so I have to doubt you have even
tried, let alone understood what you are doing.

<http://jibbering.com/faq/>
PointedEars
Nov 9 '05 #2
ML.Steve wrote:
Hi,

There are lots of posts on this subject but after a couple of hours of
going though them I still can't get a number of fields to be disabled
when a checkbox is ticked. Basically I have a lot of Forecast and
Actual dates that can be entered, and next to each one an 'NA' checkbox
that I want to disable/grey-out both dates (and the JavaScript calendar
if possible). It also only has to work on Internet Explorer 6, as it
is for internal use only.

Any help greatly welcome as this is starting to drive me mad.


Here's an example that should get you going:

<script type="text/javascript">

function disableControls (el)
{
var num = el.name.replace (/\D/g,'');
var form = el.form;
form['Forecast'+num].disabled = el.checked;
form['Actual'+num].disabled = el.checked;
}

</script>

<form name="lform" method="get" action="UpdateD B.asp">
<table border="1">
<tr>
<td><b>Forecast 1:</b>
<input type="text" name="Forecast1 "></td>
<td><b>Actual1: </b>
<input type="text" name="Actual1"> </td>
<td><input type="checkbox" NAME="NA1"
onclick="disabl eControls(this) ;"> N/A</td>
</tr>
</table>
</form>
The trick is keep the number part of name of related controls the same.
If you wanted to get more complex, you could create an object that has
the name of the checkbox and the names of the controls to
enable/disable, like:
var relatedControls = {
'NA1' : ['Actual1','Fore cast1'],
'NA2' : ['Actual2','Fore cast2']
};
Then the function could do something like:

function toggleDisabled( el)
{
var form = el.form;
var controlNames = relatedControls[el.name];
var isChecked = el.checked;
var i = controlNames.le ngth;
while (i--){
form[controlNames[i]].disabled = isChecked;
}
}

That way each checkbox could enable/disable any number of controls.

--
Rob
Nov 9 '05 #3
RobG wrote:
var num = el.name.replace (/\D/g,'');


More efficient is always:

var num = el.name.replace (/\D+/g, '');
PointedEars
Nov 9 '05 #4
Thanks for the replies;

The actual names of the fields are pretty long and detail what the date
field actually is, so looping is not an option. I have however got it
working from another post here, that I had tried before but didn't
work, but did a second time. The bit I am looking at now is disabling
the calendars, which I am completed stumped on. It would be great if I
could swap the calendar image for a disabled greyed out version which
didn't bring up the calendar.

<script language="JavaS cript" type="text/JavaScript">
function enableDisable(C heckBoxID, FieldID1, FieldID2){
document.getEle mentById(FieldI D1).disabled = (CheckBoxID.che cked);
document.getEle mentById(FieldI D2).disabled = (CheckBoxID.che cked);
return true;
}

[...]

<td><b>Forecast :</b> <input type="text"
name="DrawingsA pprovedforAcqAn dPlanForecast" id="Date14" size="10"
maxlength="10" value="<%=Drawi ngsApprovedforA cqAndPlanForeca st%>">
<img src="/images/icons/calendar.gif" id="Trig14" style="cursor:
pointer; border: 1px solid red;" title="Date selector"></td>
<td><b>Actual :</b> <input type="text"
name="DrawingsA pprovedforAcqAn dPlan" id="Date15" size="10"
maxlength="10" value="<%=Drawi ngsApprovedforA cqAndPlan%>">
<img src="/images/icons/calendar.gif" id="Trig15" style="cursor:
pointer; border: 1px solid red;" title="Date selector"></td>
<td><input type="checkbox" NAME="DrawingsA pprovedforAcqAn dPlanNA" <% If
DrawingsApprove dforAcqAndPlanN A=1 Then%> CHECKED <% End If %>
onClick="return enableDisable(t his, 'Date14', 'Date15');"
id="DrawingsApp rovedforAcqAndP lanNA"> N/A</td>

[...]

<script type="text/javascript">

var NoOfCalendars=1 5;
for(var count=1; count<=NoOfCale ndars; count=count+1 )
{
Calendar.setup(
{
inputField : "Date" + count,
button : "Trig" + count
}
)
}
</script>

Nov 9 '05 #5
Thomas 'PointedEars' Lahn wrote:
RobG wrote:

var num = el.name.replace (/\D/g,'');

More efficient is always:

var num = el.name.replace (/\D+/g, '');


or perhaps:

var num = el.name.replace (/^\w+/g,'');

I'd rather use hyphenated names and split so that the 'key' is explicit
and can contain any valid name characters (other than hyphen of course),
but there you go. :-)
--
Rob
Nov 9 '05 #6
RobG wrote:
Thomas 'PointedEars' Lahn wrote:
RobG wrote:
var num = el.name.replace (/\D/g,'');


More efficient is always:

var num = el.name.replace (/\D+/g, '');


or perhaps:

var num = el.name.replace (/^\w+/g,'');

I'd rather use hyphenated names and split so that the 'key'
is explicit [...]


With leading hyphen, I suppose, since /\w+/ does not match it.
PointedEars
Nov 9 '05 #7

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

0
1613
by: LRW | last post by:
Subject line confusing? The whole thing is confusing to me. OK, I think the root of my problem, aside from mental, is array based...but I'm not even sure what I want to do is even possible. So if I can get far enough to know that one way or the other, then I can try to figure out how to do it. But here's the situation: Page 1 I have a form with many item rows pulled from a database query. Among other fields, each row contains a...
0
2109
by: Ashish Shridharan | last post by:
Hi All, Has anyone ever tried disabling a checkbox or a radiobutton web server control in netscape ? While a textbox and a button control renders disabled, .NET adds the disabled attribute to the span tag in the case of a checkbox or a radiobutton. Effectively, these controls are not disabled in netscape.
4
2270
by: omidmottaghi | last post by:
I need to disable/enable form elements in my form. the code i was developed works fine in FF, but in IE, its behaviour is very strange!! in the form, we have a lot of checkboxes, all of them named like "xyz_np". in front of each checkbox, we have some fields, named "xyz" this is my JS code. after clicking on checkboxes:
1
2626
by: Evelyne | last post by:
I create CheckBoxes on the fly. I want to disable the CheckBoxes when they reflect Status, so the operator does not try to input anything. However, the text/label of the CheckBox gets grayed out also. How can I keep the text/label black (not grayed out) while disabling the input?
1
2814
by: kebabkongen | last post by:
Hi, I'm working on a JavaScript that is enabling / disabling a select element according to whether a checkbox is selected or not. This works fine in Firefox, but in Internet Explorer (v 6.0.2900) it appears wierd: When I disable the selevt element in IE, it continues to appear as enabled (falsely) until I try changing it. When I click on it, updates itself as grey as to indicate that it is disabled.
1
4129
by: Sofie | last post by:
hi, i have a form with a lot of fields on it. I would like to enable/disable all these fields using a checkbox. Is there a way to do this (perhaps using a loop mayb), without having to name each field and disable it - which would result in too many lines of code? Any help would be appreciated! thanks!
2
8871
by: TGEAR | last post by:
there is one check box and if it is checked, then shows several fields underneath; otherwise, several fields are hidden. the default is unchecked. anyone can share the code for this function? <table> <tr><td><input type="checkbox" name="vehicle" value="N" /><td></tr> <tr><td><input type="text" name="color" value="test" /><td></tr> <tr><td><input type="text" name="shape" value="test" /><td></tr>
1
2566
by: allamaria | last post by:
I am creating a form in Access, in the form there is a checkbox and some fields. I want to set the checkbox so, that if the user clicks on it, the fields should be enabled, if the checkbox has not been clicked, thann the fields remain disabled. Could you please help me to write the VBA-code for this procedure? Thank you!! Alla
482
28031
by: bonneylake | last post by:
Hey Everyone, Well i am not sure if this is more of a coldfusion problem or a javscript problem. So if i asked my question in the wrong section let me know an all move it to the correct place. what i am trying to display previously entered multiple fields. I am able to get my serial fields to display correctly, but i can not display my parts fields correctly. Currently this is what it does serial information 1 parts 1
0
9706
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main usage, and What is the difference between ONU and Router. Let’s take a closer look ! Part I. Meaning of...
0
10569
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. Here is my compilation command: g++-12 -std=c++20 -Wnarrowing bit_field.cpp Here is the code in...
0
10325
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that captivates audiences and drives business growth. The Art of Business Website Design Your website is...
1
10315
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For most users, this new feature is actually very convenient. If you want to control the update process,...
0
10075
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
0
6847
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert into image. Globals.ThisAddIn.Application.ActiveDocument.Select();...
0
5651
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
2
3815
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
3
2990
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating effective websites that not only look great but also perform exceptionally well. In this comprehensive...

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.