/    Sign up×
Community /Pin to ProfileBookmark

how to add show/hide button to this code

How Do i add show/hide button to the below codes?
if I checked one department, the script to show clickable button
for computer, statistics, and physics in case of the first section

and show a single button if i checked two checkboxes in the second section
for instance
a button for computer/statistics
a button for computer/physics
a button for physics/statistics
the codes

[code]<html>
<head>
<script type=”text/javascript”>

function checkboxlimit(checkgroup, limit){
var checkgroup=checkgroup
var limit=limit
for (var i=0; i<checkgroup.length; i++){
checkgroup[i].onclick=function(){
var checkedcount=0
for (var i=0; i<checkgroup.length; i++)
checkedcount+=(checkgroup[i].checked)? 1 : 0
if (checkedcount>limit){
alert(“You can only select a maximum of “+limit+” checkboxes”)
this.checked=false
}
}
}
}

</script>
</head>
<body>
<p>Select your favorite deparments below:</p>

<form id=”department” name=”department”>
<input type=”checkbox” name=”department” /> Computer<br />
<input type=”checkbox” name=”department” /> Physics<br />
<input type=”checkbox” name=”department” /> Statistics<br />
</form>

<script type=”text/javascript”>

//Syntax: checkboxlimit(checkbox_reference, limit)
checkboxlimit(document.forms.department.department, 1)

</script><p>Select your favorite two deparments below:</p>

<form id=”depart” name=”department”>
<input type=”checkbox” name=”department” /> Computer<br />
<input type=”checkbox” name=”department” /> Physics<br />
<input type=”checkbox” name=”department” /> Statistics<br />
</form>

<script type=”text/javascript”>

//Syntax: checkboxlimit(checkbox_reference, limit)
checkboxlimit(document.forms.depart.department, 2)

</script>

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

**Edited by site staff: Inserted code tags**
[code]your code here[/code]

to post a comment
JavaScript

1 Comments(s)

Copy linkTweet thisAlerts:
@JMRKERMar 26.2020 — Why do you keep trying to get a different answer to the same question?

See: [https://www.webdeveloper.com/d/389228-2-and-3-checkboxes/11]

Why not answer the last question posed on the above link?

Opening new threads is not the optimum method to get information.
×

Success!

Help @irumale 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 4.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: @Yussuf4331,
tipped: article
amount: 1000 SATS,

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

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