javascript - Add New Field to Form and Save it to database -
first problem:
i want add new field button, everytime button clicked create new field. try using jquery new in kind of programming language, can me? doing right?
html
<table> <tbody> <tr> <td> <?php $n = 0; $c = 0; echo "<select>"; do{ if($c>10){$n="";} echo "<option>".$n.$c.":00</option>"; echo "<option>".$n.$c.":30</option>"; $c++; }while($c<24); ?> </td> <td><input type="text"></td> </tr> </tbody> </table> <center><button id="addrow">add row</button></center>
script
<script> $(document).ready(function(){ $("#addrow").click(function(){ consoloe.log("asdasda"); $(tbody).append('<tr><td><?php $n = 0; $c = 0; echo "<select>"; do{ if($c>10){$n="";} echo "<option>".$n.$c.":00</option>"; echo "<option>".$n.$c.":30</option>"; $c++; }while($c<24); ?></td> <td><input type="text"></td> </tr>'); }); }); </script>
second problem:
i think need give name or id field, because need save database, can give me advice post method insert multiple records mysqli
? how can loop insert statement?
one things code first: 1. neeed close "select" element before ""
my advice solution: use jquery add new field $("#addrow").click(function(){ $(tbody).append('<tr><td><select><option>test1</option><option>test2</option></select> </tr></td>); });
then loop through form before submit can use php. fields in $_post[] suberglobal foreach($_post[] $item){ //insert field in db }
you can use ajax submit form , iterate on it's fields in jquery:
$.each("tbody tr td select", function(field){ $.post("yourphpfile.php", {name:field}, function(data){ //on success handler }); });
hope helps!
Comments
Post a Comment