php - Hide option in a select box dependant on previous choices. Options generated from SQL -
i user able select people went hiking with. have used jscript allows user add more selection boxes depending on how many people on hike. names in selection box generated database query.
i put in place stop same person being selected multiple times different selection boxes. example if option 1 in selected in first section box, should not available user in 2nd, 3rd, 4th.....selection box.
the selection boxes generated using following code
<table id="buddytable" class="form" border="1"> <tr> <td><input type="checkbox" required="required" name="chk[]" checked="checked" /></td> <td><label>buddy</label> <select name="buddy[]"> <option>solo</option> <?php if ($result->num_rows > 0) { // output data of each row while($row = $result->fetch_assoc()) { echo '<option value = "'.$row["idperson"].'">'.$row["forename"]. ' '.$row["surname"].'</option>'; //echo "name: " .$row["forename"]. " " . $row["surname"]. "<br>"; } } else { echo "0 results"; } $conn->close(); ?> </select> </td> </tr> </table>
the jscript allow more selection boxes added here
function addrowbuddy(tableid) { var table = document.getelementbyid(tableid); var rowcount = table.rows.length; if(rowcount < 10){ // limit user creating fields more limits var row = table.insertrow(rowcount); var colcount = table.rows[0].cells.length; for(var i=0; i<colcount; i++) { var newcell = row.insertcell(i); newcell.innerhtml = table.rows[0].cells[i].innerhtml; } }else{ alert("maximum number of buddies 10."); }
}
i have looked few solutions , although good, none of them inform me on how when mysql/php involved.
any hints, suggestions or guides appreciated.
if don't mind using framework, use w2ui's enum field (multi select):
http://w2ui.com/web/docs/form/fields-enum
the items array field can either pulled directly url or can predefined array.
it save hassle of creating more selection boxes select persons in 1 field.
or maybe use http://aehlke.github.io/tag-it/
Comments
Post a Comment