passing HTML embedded PHP w/ innerHTML -
i need able add additional rows following form group on click of button. php statement echos dynamic list of options select input based off records in database.
<h3>check 1:</h3> <div class="row" id="check_1"> <div class = "col-md-4 padding-top-10"> <label for="checkjobname_1" class="control-label">job/client name:</label> <select class="form-control" id="checkjobname_1" name="checkjobname_1"> <option selected disabled>choose client/job</option> <?php echo $dynamicjoblist; ?> </select> </div> <div class = "col-md-4 padding-top-10"> <label for="checknumber_1" class="control-label">check #:</label> <input type="text" class="form-control" id="checknumber_1" name="checknumber_1" placeholder="enter check #"/> </div> <div class = "col-md-4 padding-top-10"> <label for="checkamount_1" class="control-label">check amount:</label> <input type="text" class="form-control" id="checkamount_1" name="checkamount_1" placeholder="enter $amount of check"/> </div> </div>
this javascript function wrote so:
function addcheck() { check_i++; var checkdiv = document.createelement('div'); checkdiv.innerhtml = '<h3>check '+check_i+':</h3><div class="row" id="check_'+check_i+'"><div class = "col-md-4 padding-top-10"><label for="checkjobname_'+check_i+'" class="control-label">job/client name:</label><select class="form-control" id="checkjobname_'+check_i+'" name="checkjobname_'+check_i+'"><option selected disabled>choose client/job</option><?php echo $dynamicjoblist; ?></select></div><div class = "col-md-4 padding-top-10"><label for="checknumber_'+check_i+'" class="control-label">check #:</label><input type="text" class="form-control" id="checknumber_'+check_i+'" name="checknumber_'+check_i+'" placeholder="enter check #"/></div><div class = "col-md-4 padding-top-10"><label for="checkamount_'+check_i+'" class="control-label">check amount:</label><input type="text" class="form-control" id="checkamount_'+check_i+'" name="checkamount_'+check_i+'" placeholder="enter $amount of check"/></div></div>'; document.getelementbyid('checks').appendchild(checkdiv); }
but doesn't work cause if php statement embedded in html i'm trying append "checks" form-group... how it?
php complete server side language, means no
your best option json_encode array , send through ajax call, or in php top side code area.
file1:
$array = array("data1" => array() ....); echo json_encode($array);
your html (with jquery):
$.post("file1 uri" , function(data) { var json = json.parse(data); foreach (var x in json) alert("x: " + x + " json[x]" + json[x]); });
Comments
Post a Comment