javascript - Convert HTML to php array -


i have form table inside of it. want pass these values php script. best way so? i've searched has not been applicable.

this how have form formatted:

<form id="pageform" action="phpscript.php" method="post">   <table>     <tbody>       <tr>         <td><input type="text" class="nestedinput"name="txtname" value="john"></td><td><input type="text" class="nestedinput" name="txtlocation" value="north st"></td><td><input type="text" class="nestedinput" name="txtage" value="42"></td>       </tr>       <tr>         <td><input type="text" class="nestedinput"name="txtname" value="john"></td><td><input type="text" class="nestedinput" name="txtlocation" value="north st"></td><td><input type="text" class="nestedinput" name="txtage" value="42"></td>       </tr>       <tr>         <td><input type="text" class="nestedinput"name="txtname" value="john"></td><td><input type="text" class="nestedinput" name="txtlocation" value="north st"></td><td><input type="text" class="nestedinput" name="txtage" value="42"></td>       </tr>     </tbody>   </table>   <input type="button" name="btnsubmit" id="btnsubmit" value="submit"> </form> 

the jquery:

$("#btnsubmit").click(function(){    var array = [];    $(".nestedinput").each(function(n){     array[n] = $(this).val();   });    document.forms["pageform"].submit();  }); 

my php:

<?php   $array=json_decode($_post['json']);   print_r($array);     ?> 

what i'd run mysqli insert using values each input in each tr. ideas on how that?

in phpscript.php, can access these variables this:

$name = $_get['txtname'] $location = $_get['txtlocation'] $age = $_get['txtage'] 

variables submitted via form stored in global array $_get or $_post (depending on whether form uses or post. form doesn't have method attribute defining this, defaults get. more on here.).

also of note, submit button's id property should id="btnsubmit", not id="#btnsubmit".


Comments

Popular posts from this blog

yii2 - Yii 2 Running a Cron in the basic template -

asp.net - 'System.Web.HttpContext' does not contain a definition for 'GetOwinContext' Mystery -

mercurial graft feature, can it copy? -