Sunday, 15 September 2013

php - Populate triple select help needed -



php - Populate triple select help needed -

i have dropdown list triggers alter event populates sec select list via jquery , php. need is, when first event triggered, populate dropdown 2 callback info , populate dropdown 3 value of dropdown 2. need query 2 tables company_com , departments can using bring together not sure how homecoming info based on query.

i have posted code using , grateful help not sure direction go. many thanks.

jquery alter event code

$(function() { $("#dstr_dept").change(function() { $(this).after('<div id="loader"><imgages src="img/loading.gif" alt="loading files" /></div>'); $.get('loadboxdstrsubcat.php?dstrdept=' + $(this).val(), function(data) { $("#box_dstr").html(data); $('#loader').slideup(200, function() { $(this).remove(); $("#box_dstr").trigger("chosen:updated"); }); }); }); });

php code

<?php session_start(); ?> <?php include('../connections/domain.php'); $dstrdept = $_get['cltdstrdept']; $customer = $_session['kt_idcode_usr']; mysql_select_db($database_domain, $domain); $query = "select name departments code = '".$dstrdept."' order name asc"; $result = mysql_query($query) or die (mysql_error()); if (mysql_num_rows($result) > 0) { echo "<script type=text/javascript>\n"; echo "$(function() {\n"; echo "$(\".nobdstrboxes\").html('')\n"; echo "$('#dstr_dept').attr('data-placeholder', \"choose dept...\").prop('disabled', false)\n"; //echo "$(\"#box_dstr\").prop('disabled', false)\n"; //echo "$('#frtv').show()\n"; echo "});\n"; echo "</script>\n"; // returns info of departments while($row = mysql_fetch_array($result)) { echo "<option value='$row[name]'>$row[name]</option>"; } } else { echo "<script type=text/javascript>\n"; echo "$(function() {\n"; echo "$('.nobdstrboxes').html('error: there no boxes destroy in dept. please select another.').css({\"color\":\"red\", \"margin\": \"-6px 0 10px 22px\", \"font-size\": \"12px\", \"font-family\": \"verdana, geneva, sans-serif\"})\n"; echo "$('#box_dstr').attr('data-placeholder', \"no boxes display...\").prop('disabled', true)\n"; echo "});\n"; echo "</script>\n"; //echo "<option value='no boxes in dept'>no boxes in dept</option>"; } ?>

html code

<div class="fieldset"> <h1><span>select customer</span></h1> <p> <select data-placeholder="choose customer..." class="chosen-select" style="width:250px;" name="dstr_customer" id="dstr_customer"> <option value=""></option> <option value="demo">demo</option> <option value="demo2">demo2</option> <option value="demo3">demo2</option> <option value="demo4">demo2</option> </select> <span></span> <a href="javascript:void(0)" style="margin-left:10px;" class="tooltip" title="please select dept box destroyed stored.">help</a> </p> </div> <div class="fieldset"> <h1><span>select department</span></h1> <p> <select data-placeholder="choose dept..." class="chosen-select" style="width:250px;" name="dstr_dept" id="dstr_dept"> <option value=""></option> </select> <span></span> <a href="javascript:void(0)" style="margin-left:10px;" class="tooltip" title="please select dept box destroyed stored.">help</a> </p> </div> <div class="fieldset"> <h1><span>select address</span></h1> <p> <select data-placeholder="choose address..." class="chosen-select" style="width:250px;" name="dstr_address" id="dstr_address"> <option value=""></option> </select> <span></span> </p> </div> <div class="fieldset"> <h1><span>select box(es)</span></h1> <p> <select data-placeholder="choose box(es)..." class="chosen-select" name="box_dstr[]" id="box_dstr" multiple required="required"> <option value=""></option> </select> <span></span> <a style="margin-left: 12px;" href="javascript:void(0)" class="tooltip" title="please select boxes list. can select max of 20 boxes per submission.<br />.<br />you can select multiple boxes holding left ctrl on keyboard , making selection">help</a> </p> <div class="nobdstrboxes"></div> </div>

you can either utilize php resubmit page server , utilize value first select box utilize in queries populate next 2 select boxes.

or utilize ajax same thing without reloading page. have utilize javascript alter 2 select boxes on page.

php jquery

No comments:

Post a Comment