Jump to content

Limit checkbox Array in form


Fallen_angel

Recommended Posts

how can I limit the number of selected boxes to 2 in a form like the one bellow

[code]<form>
<tr><td><INPUT TYPE=CHECKBOX NAME="taste_type[]" onclick="boxchk(this,3)" VALUE="Berry">Berry</td>
                <td><INPUT TYPE=CHECKBOX NAME="taste_type[]" VALUE="Bubblegum">Bubblegum</td>
                <td><INPUT TYPE=CHECKBOX NAME="taste_type[]"VALUE="Chemical">Chemical</td>
                  <td><INPUT TYPE=CHECKBOX NAME="taste_type[]" VALUE="Citrus">Citrus</td>
                  <td><INPUT TYPE=CHECKBOX NAME="taste_type[]" VALUE="Chocolate" >Chocolate</td></tr>
</form>[/code]

Link to comment
https://forums.phpfreaks.com/topic/28423-limit-checkbox-array-in-form/
Share on other sites

If you want to do it in real time in the form, then JavaScript is the only way. If you want to do it with PHP, then handle it when the form is submitted, if more than 2 are selected, return the form with a explanation of the error so they can correct it.


printf

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.