'Validate a multi select input field in HTML using PHP and JavaScript
I have a select input field in multiple properties. I have to validate (empty check) this field in both JavaScript and PHP. My code is like:
select multiple="multiple" name="frm_supply[]>
Solution 1:[1]
multiple selection values are stored in a array . so check the length of the array and according to ur validation rule, for example for atleast 2 selection ,the length of the array should be greater than 2 and so on
Solution 2:[2]
<select name="name">
<?php
for ($i = 0; $i < $count; $i++) {
echo '<option value='$i'>$i</option>';
}
?>
</select>
Sources
This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.
Source: Stack Overflow
| Solution | Source |
|---|---|
| Solution 1 | chinni776 |
| Solution 2 | Alex Pliutau |
