php - Populate dynamically added select boxes from MySQL Database -
i got confused @ point in project. thing trying create here following:
get info database create new select box button - create populate select box values database alternative delete select box through button - delete
the code have far php/html:
<button type="button" name="add" onclick="return false;" id="addfield" class="nice_button">Добавить(add)</button> <button type="button" name="remove" onclick="return false;" id="remove" class="nice_button">Удалить(delete)</button> <tbody id="documentfields"> <tr> <td> <select size="1" name="hardware[]" style='width:400px;'> <option value=""></option> <?php while($hardware = $get_hardware->fetch_array()){ echo "<option value='".$hardware['st_id']."'>".$hardware['st_name']." ".$hardware['st_producer']." ".$hardware['st_model']."</option>"; } ?> </select> </td> </tr> </tbody>
js script have far looks that:
var g = 1; var id = [ <? php echo $js_id; ?> ]; $(document).ready(function product_add() { $("#addfield").click(function () { $("#documentfields").append('<tr id="fieldset_p' + g + '"><td><select size="1" name="hardware[]" style="width:400px;"><option value=""></option></select></td></tr>'); g++; }); }); $(document).ready(function product_add() { $('#remove').click(function () { // similar previous, when click remove link if (g > 1) { // if have @ to the lowest degree 1 input on form g--; //deduct 1 if = 3, after i--, = 2 $('#fieldset_p' + g + '').remove(); //remove lastly fieldset } }); });
the thing cannot append php function: while, cannot populate select box 1 before.
in case utilize ajax.
what's ajax:
http://en.wikipedia.org/wiki/ajax_(programming)
it's providing page info in specific format. phone call javascript , parse page.
documentation how in jquery:
http://api.jquery.com/jquery.ajax/
update:
code example:
$.get('ajax/test.html', function(data) { // read in info = = [{'option':'option 1'},{'option':'option 2'}] $.each(data, function(index, itemdata) { /// stuff $('<option>' + itemdata.option + '</option>').appendto('#myselectbox'); }); });
php javascript
No comments:
Post a Comment