/    Sign up×
Community /Pin to ProfileBookmark

Need help with checkbox

Dear all, I’m new to this forum. Thanks for reading this post.

I’m trying to resolve a problem which I need to insert some javascript codes in a PHP script so that it would handle this special case. This special case is described as below:

I have 5 checkboxes on the page, that’s say that they were named as checkbox1, checkbox2, checkbox3, ..etc. By default they are all “unchecked.” If the user click on “checkbox1”, then I want to force “checkbox3” to be also “checked,” and checkbox3 will also be disabled (grayed out, so that it can NOT be unchecked). Of course if checkbox1 is unchecked again, the it will “free out” checkbox3 so that it will no longer be disabled. Could anyone please give me some sample codes about how this could be implemented? Thanks!

to post a comment
JavaScript

1 Comments(s)

Copy linkTweet thisAlerts:
@tirnaApr 16.2010 — Maybe use this:

[code=php]
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN"
"http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<title></title>
<script type="text/javascript">
<!--

function enableDisable(status) {
if(status) {
document.getElementById("chk3").checked = 'checked';
document.getElementById("chk3").disabled = true;
} else {
document.getElementById("chk3").checked = null;
document.getElementById("chk3").disabled = false;
}
}

//-->
</script>

</head>
<body>

<div>
<input type="checkbox" name="chk1" id="chk1" onclick="enableDisable(this.checked);" /> Chk Box 1
<input type="checkbox" name="chk2" id="chk2" /> Chk Box 2
<input type="checkbox" name="chk3" id="chk3" /> Chk Box 3
</div>

</body>
</html>
[/code]
×

Success!

Help @ohman 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 5.18,
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: @AriseFacilitySolutions09,
tipped: article
amount: 1000 SATS,

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

tipper: @darkwebsites540,
tipped: article
amount: 10 SATS,
)...