6
Contributors
11
Replies
13
Views
6 Years
Discussion Span
Last Post by ashiiiish
0

Checkboxes are limited via HTML.. They'll be already limited when they appear in the page you create.

Edited by Pro2000: n/a

0

suppose i am posting 5 checkboxes and i want users to select any 3 of them then how to do it???

0

You need JS. If you're using jQuery, you could do something like this (if not, it's the same thing but it would take quite a bit more coding):

$('input:checkbox').click(function(){
  $('input:checkbox:not(:checked)').attr('disabled', $('input:checkbox:checked').length >= 3 ? 'disabled' : '');
});
0

my code is too long its about 327 checkboxes in different section i need to limit the selection in all of the sections

its simply lyk i hav putd some checkboxs and nothing and is using php for other things and nothing else

0

Well, you could also count the amount of selected boxes with php and echo a warning if it's > 3, of course, but personally I'd definitely use JS for this.

0

Try this code It using Java script

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1" />
<title>Untitled Document</title>
<script>
function check()
{
var len=document.f.ck.length;
var ck=document.f.ck;
var l=0;
for(var i=0;i<len;i++)
{
if(ck[i].checked==true)
{
l++;
}
if(l>3)
{
ck[i].checked = false ;
}
}



}
</script>
</head>

<body>
<form id="form1" name="f" method="post" action="">
  <p>
    <input name="ck" type="checkbox" id="ck" value="checkbox" onclick="check()"/> 
  PHP</p>
  <p>
    <input name="ck" type="checkbox" id="ck" value="checkbox" onclick="check()"/> 
  JSP</p>
  <p>
    <input name="ck" type="checkbox" id="ck" value="checkbox" onclick="check()"/> 
  JAVA</p>
  <p>
    <input name="ck" type="checkbox" id="ck" value="checkbox" onclick="check()"/> 
  CSS</p>
  <p>
    <input name="ck" type="checkbox" id="ck" value="checkbox" onclick="check()" /> 
    HTML</p>
  <p>
    <input type="submit" name="Submit" value="Submit" />
  </p>
</form>
</body>
</html>
0

I think it's more user friendly to disable the checkboxes, but well. That's a possibility too.

This question has already been answered. Start a new discussion instead.
Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.