PDA

View Full Version : Check and Uncheck -


ClueLess
11-08-2002, 02:51 PM
What is wrong with this script? It seems like work fine. But when I check the checkbox, it shows “Error on page.” How can I fix this error? Thanks for your help


<html>
<head>
<title>Untitled</title>
</head>

<body>
<script LANGUAGE="JavaScript">
agree = 0; // 0 means 'no', 1 means 'yes'
// Yes = allowing users enter new info.
// No = Not allowing users enter any info.
</script>
<form action="InfoEdit.asp" method="post" name="SubmitForm" onsubmit="ShowAmendmentDate()">
<legend class="largeHeadingBlack"><em>Information</em></legend>
<table border='0'>
<tr>
<td width="40" align="right" class="regularParagraph">
<input type="checkbox" name='accepted' value='agree' onClick="agree=1; documentwin.SubmitForm.box.focus();">
</td>
<td width="250" class="regularParagraph">
<font color="red"><em><b>Check before Add New Information</b></em></font>
</td>
</tr>
<tr>
<td width="40" align="right" class="SmallHeadingBurg">&nbsp;<font color="red">*</font></td>
<td class="SmallHeadingBurg" width="180"> Name:&nbsp;</td>
<td class="regularParagraph" align="left">
<input type="text" id="LPName" name="LPName" value="" onFocus="if (!agree)this.blur();" maxlength="30" size="38">
</td>
</tr>
<tr>
<td>
<input type="submit" value="Update" name="Update" onclick="DoConfirm()" class="ActionButton">&nbsp;&nbsp;&nbsp;
</td>
</tr>
</table>


</body>
</html>

aEr_aEr
11-08-2002, 02:59 PM
documentwin.SubmitForm.box.focus();
what is documentwin?
try document

what is box?
cannot be found in your code

ClueLess
11-08-2002, 03:20 PM
Oops, my bad.

I tried to test it......but forgot removing them before posting my code. I did remove the “win” and “box”; it works now.

I have another problem, when I uncheck it but I still can enter something in the textbox. Is there any way that does not let users enter something in there…… unless they have to check the checkbox?

aEr_aEr
11-08-2002, 03:25 PM
try something like this

<input type="checkbox" name='accepted' value='agree' onClick="disable(this)">
<script>
function disable(obj){
if (obj.checked)
document.all.LPName.disabled=false;
else
document.all.LPName.disabled=true;
}
</script>



or shorter version

<input type="checkbox" name='accepted' value='agree' onClick="disable(this)">
<script>
function disable(obj){
document.all.LPName.disabled=(!obj.checked);
}
</script>

dont know for sure if this works

ClueLess
11-08-2002, 04:21 PM
aEr_aEr ,
It doesn't work. It disables everything

:(

aEr_aEr
11-11-2002, 06:42 AM
I tried it and this works fine:

I changed the name of the function


<html>
<head>
<title>Untitled</title>
</head>

<body>
<script LANGUAGE="JavaScript">
agree = 0; // 0 means 'no', 1 means 'yes'
// Yes = allowing users enter new info.
// No = Not allowing users enter any info.
</script>
<form action="InfoEdit.asp" method="post" name="SubmitForm" onsubmit="ShowAmendmentDate()">
<legend class="largeHeadingBlack"><em>Information</em></legend>
<table border='0'>
<tr>
<td width="40" align="right" class="regularParagraph">
<input type="checkbox" name='accepted' value='agree' onClick="doda(this)">
</td>
<td width="250" class="regularParagraph">
<font color="red"><em><b>Check before Add New Information</b></em></font>
</td>
</tr>
<tr>
<td width="40" align="right" class="SmallHeadingBurg"> <font color="red">*</font></td>
<td class="SmallHeadingBurg" width="180"> Name: </td>
<td class="regularParagraph" align="left">
<input type="text" id="LPName" name="LPName" value="" maxlength="30" size="38" disabled>
</td>
</tr>
<tr>
<td>
<input type="submit" value="Update" name="Update" onclick="DoConfirm()" class="ActionButton">
</td>
</tr>
</table>


</body>
</html>
<script>
function doda(obj){
if (obj.checked)
document.all.LPName.disabled=false;
else
document.all.LPName.disabled=true;
}
</script>

ClueLess
11-11-2002, 03:17 PM
Supper!!! Thanks. It works