jquery - Get values from dynamically created fields and send them to PHP via Ajax -


i have page text field field name , 2 buttons (insert field, show fields).

the user inserts value inside of first text field that's going new field's name. when clicks on insert field value going send database , inserted table called tbl_fields.

and when user clicks on show fields, page loads field names tbl_fields , creates n text fields it's placeholders containing names loaded.

these fields shown inside of .fieldlist div contains button insert values , when user clicks on it, want values these dynamically created fields it's placeholders , insert them database table called tbl_values, table has 3 columns, id, field_name represents name (placeholder) of field , field_value represents value of field.

so question is, how can values , placeholders these dynamically created fields , send them .php file via ajax? know can use .val() it's value , .attr('placeholder') placeholder that's not point, problem don't know how many fields there nor how can acess them $_post.

this have far, here's script.js:

$(document).ready(function(){      var fieldcount = 0;      $("#btnfieldsend").click(function(){          if($("#txtfieldname").val()) {              $.ajax({                  type: 'post',                 datatype: 'json',                 url: 'insertfield.php',                 data: { txtfieldname: $("#txtfieldname").val() }             }).done(function(data){                  if(data.ok) {                      $("#txtfieldname").val('');                     alert(data.ok);                 }                 else                     alert(data.err);             })         }     });      $("#btnfields").click(function(){          if($(".fieldlist").is(":hidden")) {              $.ajax({                  datatype: 'json',                 url: 'selectfield.php'             }).done(function(data){                  if(data.ok) {                      fieldcount = data.fieldcount;                      for(var = 0; < fieldcount; i++)                         $(".appfield").append('<input id="' + + '" type="text" placeholder="' + data.fieldname[i][0] + '">');                      $(".fieldlist").show();                 }                 else                     alert(data.err);             });         }     });      $("#insertvalues").click(function(){          // send values     }); }); 

please, notice i'm not asking me, know i'm not providing code $("#insertvalues").click() going values fields , send them php, , lacks php code going receive it. i'm stuck , don't know or how proceed, need guide me way solve this.

if need me show html, insertfield.php, selectfield.php or maybe sql script, let me know.

give of inputs name attribute can sent through backend.

you can send through form whole, if weren't via ajax $('#formid').serialize() specified ajax function's data attribute.


Comments

Popular posts from this blog

amazon web services - S3 Pre-signed POST validate file type? -

c# - Check Keyboard Input Winforms -