jquery - How to insert php variables from another file to a form with ajax -
pls i'm trying insert variable values php file html file using ajax don't know how start here form
<form> <table> <tr> <td>full name</td> <td><input type = 'text' name = 'fullname' id = 'fullname'></td> <td>cuid</td> <td><input type = 'text' name = 'idno' ></td> </tr> <tr> <td>surname</td> <td><input type = 'text' name = 'sname' id = 'sname'></td> <td>title</td> <td> <select name='title'> <option>select title</option> <?php $conn = db(); $stmt=$conn->prepare('select title titles order title'); $stmt->execute(); while($data = $stmt->fetch()){ echo "<option>".$data['title']."</option>"; } ?> </select> </td> </tr> <tr> <td>first name</td> <td><input type = 'text' name = 'fname' id = 'fname'></td> </tr> <tr> <td>middle name</td> <td><input type = 'text' name = 'mname' id = 'mname'></td> </tr> <tr> <td>designation</td> <td> <select name='post' id ='post'> <option>select post</option> <?php $conn = db(); $stmt=$conn->prepare('select post posts order post'); $stmt->execute(); while($data = $stmt->fetch()){ echo "<option>".$data['post']."</option>"; } ?> </select> </td> </tr> <tr> <td>gender</td> <td> <select name='gender'> <option>select gender</option> <?php $conn = db(); $stmt=$conn->prepare('select sex sx order sex'); $stmt->execute(); while($data = $stmt->fetch()){ echo "<option>".$data['sex']."</option>"; } ?> </select> </td> <td>date of resumption</td> <td><input type = 'date' name = 'dresume' id = 'dresume'></td> <td>category</td> <td> <select onchange='bn(this.value);' name='category'> <option>select category</option> <?php $conn = db(); $stmt=$conn->prepare('select category categories order category'); $stmt->execute(); while($data = $stmt->fetch()){ echo "<option>".$data['category']."</option>"; } ?> </select> </td> </tr> <tr> <td>department</td> <td> <select name='unit'> <option>select department</option> <?php $conn = db(); $stmt=$conn->prepare('select department units order department'); $stmt->execute(); while($data = $stmt->fetch()){ echo "<option>".$data['department']."</option>"; } ?> </select> </td> <td>unit</td> <td><input type = 'text' name = 'unit' id = 'unit'></td> <td>kol</td> <td><input type = 'text' name = 'kol' id = 'kol'></td> </tr> <tr> <td>level</td> <td> <select name='level' > <option>select level</option> <?php $conn = db(); $stmt=$conn->prepare('select level levels'); $stmt->execute(); print_r ($stmt); while($data = $stmt->fetch()){ echo "<option>".$data['level']."</option>"; } ?> </select> </td> <td>step</td> <td> <select name='step'> <option>select step</option> <?php $conn = db(); $stmt=$conn->prepare('select step steps'); $stmt->execute(); print_r ($stmt); while($data = $stmt->fetch()){ echo "<option>".$data['step']."</option>"; } ?> </select> </td> <td>salary scale</td> <td><input type = 'text' name = 'sscale' id = 'sscale'></td> </tr> <tr> <td>responsiblity/duty posy</td> <td><input type = 'text' id = 'dutypost' name = 'dutypost'></td> <td>responsiblity alowance</td> <td><input type = 'text' id = 'rallowance' name = 'rallowance'></td> </tr> <tr> <td>special payment</td> <td><input type = 'text' id = 'spayment' name = 'spayment'></td> <td>pay percentage</td> <td><input type = 'text' id = 'ppercent' name = 'ppercent'></td> </tr> <tr> <td>house deduction</td> <td><input type = 'text' id = 'hded' name = 'hded'></td> <td>rent deduction</td> <td><input type = 'text' id = 'rded' name = 'rded'></td> <td>furniture deduction</td> <td><input type = 'text' id = 'fded' name = 'fded'></td> </tr> <tr> <td>nhf</td> <td><input type = 'text' id = 'nhf' name = 'nhf'></td> <td>nhf_no</td> <td><input type = 'text' id = 'nhfno' name = 'nhfno'></td> </tr> <tr> <td>pfa</td> <td><input type = 'text' id = 'pfa' name = 'pfa'></td> <td>pfa_no</td> <td><input type = 'text' id = 'pfano' name = 'pfano'></td> </tr> </table> </form>
when edit button clicked these varibale automatically appear in form pls i'll need head start @ still new @ here php file
if(isset($_post['edit'])) { $dresume = $data['dresume']; $kol = $data['kol']; $level = $data['level']; $step = $data['step']; $dpost = $data['dutypost']; $dpay = $data['dutypay']; $spay = $data['special']; $ppercent = $data['paypercent']; $rentd = $data['hdedp']; $house = $data['house']; $furnided = $data['furnided']; $nhf = $data['nhf']; $nhfno = $data['nhf_no']; $pfa = $data['pfa']; $pfano = $data['pfa_no']; }
the basic thing should understand php executes in server , cannot execute php script in html once page loaded.
now have doubt how did php written inside html worked? answer file got parsed in server , php script written in between "" executed , corresponding html generated, see source of html in browser.
once page served browser php code not execute. modification in html loaded in browser, either need reload page or need client script executes in browser. javascript can used client script.
ajax method of communication between html loaded in browser , server. ie, if want send data or html loaded in browser, can make use of ajax. https://webdesignerhut.com/pass-data-with-ajax-to-a-php-file/ example
you can find , better documentations before start
Comments
Post a Comment