/    Sign up×
Community /Pin to ProfileBookmark

How to reset the "unclick value"?

I want to use one checkbox to enable and disable the other two checkboxes. When user click the two checkboxs, it keep the “click value” in it. How to reset the “unclick value” when the user click the other checkbox?

<html>
<head>
<script type=”text/javascript”>
function changer() {
if(this.form2.activator.checked){
this.form2.decision[0].disabled=false;
this.form2.decision[1].disabled=false;
}
else{
this.form2.decision[0].disabled=true;
this.form2.decision[1].disabled=true;
}
}
</script>
</head>
<body>
<table width=”400″ border=”1″ cellpadding=”0″ cellspacing=”0″>
<form name=”form2″ method=”post” action=””>
<tr>
<td colspan=”3″> <input type=”checkbox” name=”checkbox” value=”checkbox”>
A<br>
<input type=”checkbox” name=”checkbox” value=”checkbox”>
B<br>
<input type=”checkbox” name=”activator” value=”checkbox” onClick=”changer()”>
C<br>
</tr>
<tr>
<td width=”100″><input type=”checkbox” name=”decision” value=”first” disabled=”true”>
Oral </td>
<td width=”100″><input type=”checkbox” name=”decision” value=”second” disabled=”true”>
Written</td>
</tr>
</form>
</table>
</body>
</html>

to post a comment
JavaScript

6 Comments(s)

Copy linkTweet thisAlerts:
@KorMar 02.2005 — Why don't u simply use 2 radio buttons with same name? Thus when one is checked, the other is unchecked...
Copy linkTweet thisAlerts:
@fisher999authorMar 02.2005 — Because I hope the user can choose two boxes at the same times. BTW, How to clear the image in the other two checkboxes? Like the Pic below?

[IMG]http://hk.geocities.com/robotcat2001/1.jpg[/IMG]
Copy linkTweet thisAlerts:
@KorMar 02.2005 — [i]Originally posted by fisher999 [/i]

Because I hope the user can choose two boxes at the same times. [/QUOTE]


This case you [b]must[/b] give them different names, otherwise you will get trouble with passing values on submit.


To "uncheck" the checkboxes use [b]checked[/b] attribute.

[code=php]
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
<title>Untitled Document</title>
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1">
<meta http-equiv="Content-Style-Type" content="text/css">
<meta http-equiv="Content-Script-Type" content="text/javascript">
<script type="text/javascript">
function changer(f) {
if(f.activator.checked){
f.decision0.disabled=false;
f.decision1.disabled=false;
f.checkbox0.checked=false;
f.checkbox1.checked=false;
}
else{
f.decision0.disabled=true;
f.decision1.disabled=true;
f.decision0.checked=false;
f.decision1.checked=false;
}
}
</script>
</head>
<body>
<table width="400" border="1" cellpadding="0" cellspacing="0">
<form name="form2" method="post" action="">
<tr>
<td colspan="3"> <input type="checkbox" name="checkbox0" value="checkbox0">
A<br>
<input type="checkbox" name="checkbox1" value="checkbox1">
B<br>
<input type="checkbox" name="activator" value="checkboxa" onClick="changer(this.form)">
C<br>
</tr>
<tr>
<td width="100"><input type="checkbox" name="decision0" value="first" disabled="true">
Oral </td>
<td width="100"><input type="checkbox" name="decision1" value="second" disabled="true">
Written</td>
</tr>
</form>
</table>
</body>
</html>
[/code]
Copy linkTweet thisAlerts:
@fisher999authorMar 02.2005 — Thanks Kor!

But one problem is: when I click A and B first, and click C, then the clicks in A and B will be off... how to keep the clicks in A and B even click C checkbox?
Copy linkTweet thisAlerts:
@KorMar 02.2005 — <script type="text/javascript">

function changer(f) {

if(f.activator.checked){

f.decision0.disabled=false;

f.decision1.disabled=false;

}

else{

f.decision0.disabled=true;

f.decision1.disabled=true;

f.decision0.checked=false;

f.decision1.checked=false;

}

}

</script>
Copy linkTweet thisAlerts:
@fisher999authorMar 02.2005 — Many thanks KOR!!!!!
×

Success!

Help @fisher999 spread the word by sharing this article on Twitter...

Tweet This
Sign in
Forgot password?
Sign in with TwitchSign in with GithubCreate Account
about: ({
version: 0.1.9 BETA 6.16,
whats_new: community page,
up_next: more Davinci•003 tasks,
coming_soon: events calendar,
social: @webDeveloperHQ
});

legal: ({
terms: of use,
privacy: policy
});
changelog: (
version: 0.1.9,
notes: added community page

version: 0.1.8,
notes: added Davinci•003

version: 0.1.7,
notes: upvote answers to bounties

version: 0.1.6,
notes: article editor refresh
)...
recent_tips: (
tipper: @nearjob,
tipped: article
amount: 1000 SATS,

tipper: @meenaratha,
tipped: article
amount: 1000 SATS,

tipper: @meenaratha,
tipped: article
amount: 1000 SATS,
)...