Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations bkrike on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

disable checkbox unless all text areas are populated 1

Status
Not open for further replies.

smurf01

IS-IT--Management
Jul 6, 2002
470
GB
Hi Guru's,

I have a checkbox which is called 'completeCB' and what I need is for this checkbox to be disabled unless the three text areas I have on the form are all populated. I have loooked through the forum but cannot find anything to help me.

the text areas are named as follows

Investigate
CatTaken
PatTaken

Any help would be appreciated [ponder] [ponder] [ponder]

Regards

Paul
 
Try this:

Code:
<html><head>
	<title></title>
</head><body>

<script language="javascript">

function checkEntries ()
{
	if (document.frmMain.Textarea1.value.length > 0 && document.frmMain.Textarea2.value.length > 0 && document.frmMain.Textarea3.value.length > 0)
	{
		document.frmMain.chkBx.disabled = false;
	}
	else
	{
		document.frmMain.chkBx.disabled = true;
	}
}

</script>

<form name="frmMain">

	<input type="checkbox" id="chkBx" disabled="true"><br>
	<textarea id="Textarea1" rows="4" cols="50" onchange="checkEntries ();"></textarea><br>
	<textarea id="Textarea2" rows="4" cols="50" onchange="checkEntries ();"></textarea><br>
	<textarea id="Textarea3" rows="4" cols="50" onchange="checkEntries ();"></textarea><br>

</form>

</body></html>

- VB Rookie
 
VBRookie,
Thats great, i have one problem though,if after data is entered into all three text areas and the checkbox is ticked, you can then delete info from one or all of the text areas and it disables the checkbox with it still ticked.I know this may sound silly but once the checkbox is ticked could I disable the text areas until the checkbox is cleared

Regards

Paul
 
Try this:

Code:
<html><head>
	<title></title>
</head><body>

<script language="javascript">

function checkEntries ()
{
	if (document.frmMain.Textarea1.value.length > 0 && document.frmMain.Textarea2.value.length > 0 && document.frmMain.Textarea3.value.length > 0)
	{
		document.frmMain.chkBx.disabled = false;
	}
	else
	{
		document.frmMain.chkBx.disabled = true;
	}
}

function disableTextAreas ()
{
	if (document.frmMain.chkBx.checked)
	{
		document.frmMain.Textarea1.disabled = true;
		document.frmMain.Textarea2.disabled = true;
		document.frmMain.Textarea3.disabled = true;
	}
	else
	{
		document.frmMain.Textarea1.disabled = false;
		document.frmMain.Textarea2.disabled = false;
		document.frmMain.Textarea3.disabled = false;
	}
}
</script>

<form name="frmMain">

	<input type="checkbox" id="chkBx" onclick="disableTextAreas ();" disabled="true"><br>
	<textarea id="Textarea1" rows="4" cols="50" onchange="checkEntries ();"></textarea><br>
	<textarea id="Textarea2" rows="4" cols="50" onchange="checkEntries ();"></textarea><br>
	<textarea id="Textarea3" rows="4" cols="50" onchange="checkEntries ();"></textarea><br>

</form>

</body></html>

- VB Rookie
 
VBRookie,
since I posted my message back I have been trying to sort it myself and I had come up with this which is almost identical to your suggestion
Code:
<script language="javascript">
function dt()
{
if (document.calform.CompleteCB.checked)
{
document.calform.InvestResultT.disabled=true;
document.calform.CATakenTB.disabled=true;
document.calform.PATakenTB.disabled=true;
}
else
{
document.calform.InvestResultT.disabled=false;
document.calform.CATakenTB.disabled=false;
document.calform.PATakenTB.disabled=false;
}
}

</script>

and for the checkbox I had

<input type="checkbox" id="CompleteCB" onclick="dt()">

you will notice I missed out the semicolon or is it colon I can never remember anyway, it would not work for me.

I am just going to try yours and I will let you know. Thanks for the help up to now it is much appreciated

[2thumbsup] :-D [2thumbsup]


Regards

Paul
 
VBRookie,
I put all of your code into a test page and it worked fine, therefore i knew that I must have some coding wrong somewhere in mine. So what i did was to rewrite the code and now it works perfectly.

Thanks so much for your help

[2thumbsup]:-D[2thumbsup]

Regards

Paul
 
WOW !!!
Spoke to soon the disabling of the text areas works fine however, because this is an update form it is not updating the disabled text areas to the underlying table is there any way i can still do this

Regards

Paul
 
OK sorted now, changed the code from 'disable' to 'readOnly' and it seems to be working

Regards

Paul
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top