Jump to content
Fórum Script Brasil
  • 0

Restringir Qtde De Checkbox Selecionados?


iel

Question

Ai pessoal seguinte eu tenho este codigo e ele não ta dando certo, algum poderia me dar uma luz do porque não ta funcionando!

valeu heim!

<html>
<head>
<title>Teste</title>
<script>
function validacao(obj){ 
for(i=0;i<obj.length-1;i++)
{
if (obj.elements[i].cb >= 0) 
{
itens=0;
de = i;
ate = eval(de) + eval(obj.elements[i].cb);
for (x=de; x<=ate; x++)
{
if(obj.elements[x].checked)
{
itens++;
}
}
if (itens > 8)
{
alert("SELECIONE NO MAXIMO 8" );
obj.elements[i].focus();
return false;
}
}
}
} 
</script>

</head>

<body>
<form name="form1" method="post" action="">
  <table width="50%" border="1" cellspacing="0" cellpadding="0">
    <tr> 
      <td colspan="5">Escolha as op&ccedil;&otilde;es</td>
    </tr>
    <tr> 
      <td><input name="itens" type="checkbox" id="itens" value="item1" cb="19">
        Item1</td>
      <td><input name="itens" type="checkbox" id="itens" value="item2">
        Item2</td>
      <td><input name="itens3" type="checkbox" id="itens" value="item3">
        Item3</td>
      <td><input name="itens4" type="checkbox" id="itens" value="item4">
        Item4</td>
      <td><input name="itens5" type="checkbox" id="itens" value="item5">
        Item5</td>
    </tr>
    <tr> 
      <td><input name="itens6" type="checkbox" id="itens" value="item6">
        Item6</td>
      <td><input name="itens7" type="checkbox" id="itens" value="item7">
        Item7</td>
      <td><input name="itens8" type="checkbox" id="itens" value="item8">
        Item8</td>
      <td><input name="itens9" type="checkbox" id="itens" value="item9">
        Item9</td>
      <td><input name="itens10" type="checkbox" id="itens" value="item10">
        Item10</td>
    </tr>
    <tr> 
      <td><input name="itens11" type="checkbox" id="itens" value="item11">
        Item11</td>
      <td><input name="itens13" type="checkbox" id="itens" value="item12">
        Item12</td>
      <td><input name="itens15" type="checkbox" id="itens" value="item13">
        Item13</td>
      <td><input name="itens17" type="checkbox" id="itens" value="item14">
        Item14</td>
      <td><input name="itens19" type="checkbox" id="itens" value="item15">
        Item15</td>
    </tr>
    <tr> 
      <td><input name="itens12" type="checkbox" id="itens" value="item16">
        Item16</td>
      <td><input name="itens14" type="checkbox" id="itens" value="item17">
        Item17</td>
      <td><input name="itens16" type="checkbox" id="itens" value="item18">
        Item18</td>
      <td><input name="itens18" type="checkbox" id="itens" value="item19">
        Item19</td>
      <td><input name="itens20" type="checkbox" id="itens" value="item20">
        Item20</td>
    </tr>
  </table>
  <p>
    <input type="submit" name="Submit" value="Enviar" onSubmit="return validacao(this)">
  </p>
</form>
</body>
</html>

Link to comment
Share on other sites

1 answer to this question

Recommended Posts

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Answer this question...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.



  • Forum Statistics

    • Total Topics
      152.2k
    • Total Posts
      652k
×
×
  • Create New...