ඇයි ajax වලින් එන response එක දෙවෙනි dropdown එකට එකතු වෙන්නෙ &#
මෙතන dropdowns ඩෙකක් තියෙනවා (ඩෙකක් නෙමයි දෙකක්
). පලවෙනි එකේ values db table එකකින් ගන්නෙ. දෙවෙනි එකෙ values වෙනස් වෙනවා first dropdown එකෙ තොරන දෙය අනුව .
පලවෙනි dropdown එක
දෙවෙනි එක.
JS
PHP code
Console එකේ print වෙනවා මචන්ලා හරියට.එත් දෙවෙනි dropdown එකට එන්නෙ නැහැනේ. ajax success එකේ alert කලාම <option> tags වලට අම්තරව මුලු html file එකම එනවා.
මෙතන dropdowns ඩෙකක් තියෙනවා (ඩෙකක් නෙමයි දෙකක්
). පලවෙනි එකේ values db table එකකින් ගන්නෙ. දෙවෙනි එකෙ values වෙනස් වෙනවා first dropdown එකෙ තොරන දෙය අනුව . පලවෙනි dropdown එක
HTML:
<div class="formBlock"> <label for="branch_id">Branch Name<span class="required">*</span></label> <select id="branch_id" name="branch_id" class="textInput"> <?php $branches = $branch->find_by_sql("SELECT * FROM branch");//this is an arry foreach ($branches as $branch) { echo "<option value='$branch->id'>$branch->branch_name</option> "; } ?> </select> </div>
දෙවෙනි එක.
HTML:
<div class="formBlock"> <label for="cust_id">Customer Name <span class="required">*</span></label> <select id="cust_id" ></select> </div>
Code:
$(function(){ $("#branch_id").bind("change",function(){ $.ajax({ type:"GET", url:"create_loan_request.php", //same file data:"branch_id="+$("#branch_id").val(), dataType:"text", //changed this to html also success:function(html){ $("#cust_id").html(html); // I have tried append also console.log(html); //inserting options to second dropdown }, error: function(jqXHR, textStatus, errorThrown) { console.log(textStatus, errorThrown); } }); });
PHP:
if(isset($_GET["branch_id"])){ $id=(int)$_GET["branch_id"]; $customers= Customer::find_by_sql("SELECT id,firstname,lastname FROM customer WHERE branch_id=".$id); foreach ($customers as $customer) { echo "<option value='$customer->id'>".$customer->firstname."</option>"; } }

