jquery - How to create combobox in php mysql? -
i have dropdown select shows mysql records. want create dropdown select have combobox.
bid.php
<script type="text/javascript" src="javascript/jquery.js"></script> <script> function showuser(str) { var $txthint = $('#txthint'); if (str == "") { $txthint.html(''); return; } $txthint.load('bid_list.php?q=' + str) } </script> </head> <body onload=showuser(str="all")> <div id="main" style="width:1150px;margin:0 auto;padding:10px;"> <div id="title" style="width:1150px;margin:0 auto;text-align:center;font-size:30px;color:gray;text-shadow:2px 2px #000;font-family:verdana, tahoma, sans-serif;"><h3>bidding list</h3></div> <div id="container" style="width:1100px;"> <?php $mysqli = new mysqli("localhost", "root", "", "app"); $result = $mysqli->query("select bid procurement bid '13-___' or bid '1_-___' or bid '2_-___' group bid order bid"); $option = ''; while($row = $result->fetch_assoc()) { $option .= '<option value = "'.$row['bid'].'">'.$row['bid'].'</option>'; } ?> <div style="text-align:center;"> <select name="users" onchange="showuser(this.value)" style="overflow:scroll;width:100px;"> <option value="all" selected='all'>all</option> <?php echo $option; ?> </select> </div> <br> <div id="txthint"></div>
bid_list.php
<html> <head> <title></title> <link rel="stylesheet" href="css/style.css" type="text/css" id="" media="print, projection, screen" /> <script type="text/javascript" src="javascript/jquery.tablesorter.js"></script> <script type="text/javascript"> $(function() { $("table").tablesorter({debug: true}); }); </script> <script type="text/javascript"> $(function(){ var tfrow = document.getelementbyid('tfhover').rows.length; var tbrow=[]; (var i=1;i<tfrow;i++) { tbrow[i]=document.getelementbyid('tfhover').rows[i]; tbrow[i].onmouseover = function(){ this.style.backgroundcolor = '#f3f8aa'; }; tbrow[i].onmouseout = function() { this.style.backgroundcolor = '#ffffff'; }; } }); </script> </head> <body> <?php $mysqli = new mysqli("localhost", "root", "", "app"); $q = $_get["q"]; $where = ''; if ( $q != 'all' ) { $where = " bid='$q' "; } $result1 = $mysqli->query(" select bid, item_name, item_description, unit, unit_cost, quantity, supplier, po_number, po_date, counter, sum(unit_cost*quantity) total_amount procurement $where group counter order bid "); echo'<table id="tfhover" cellspacing="0" class="tablesorter" style="text-transform:uppercase;"> <thead> <tr> <th title="item name">item name</th> <th title="item description">description</th> <th title="example : pc, pcs, box , etc.">unit</th> <th title="item price">unit cost</th> <th title="total item quantity">qty</th> <th title="total price">total amount</th> <th title="name of supplier">supplier</th> <th title="purchase order #">po #</th> <th title="purchase order date">po date</th> </tr> </thead>'; echo'<tbody>'; while($row = $result1->fetch_assoc()){ if($row['bid'] != '') { echo'<tr> <td>'.$row['item_name'].'</td> <td>'.$row['item_description'].'</td> <td>'.$row['unit'].'</td> <td>'.number_format($row['unit_cost'], 2, '.', ',').'</td> <td>'.$row['quantity'].'</td> <td>'.number_format($row['total_amount'], 2, '.', ',').'</td> <td>'.$row['supplier'].'</td> <td>'.$row['po_number'].'</td> <td>'.$row['po_date'].'</td> </tr></tbody>'; } } echo "</table>"; if (!$mysqli) { die('connect error: ' . mysqli_connect_error()); } mysqli_close($mysqli); ?> </body> </html>
what want if dropdown value equal 13-001 second dropdown shows po_number, if choose in 2nd dropdown records of po_number 12-12-co 397 shows in table. how that?
i figured out myself, hope helps you.
in view:
<script src="http://code.jquery.com/jquery-1.9.1.js"></script> <script src="/js/dynamicselect.js"></script> <script> $( document ).ready(function() { $("#selecttoupdate").dynamicselect($("#changetriggersupdate"),"actionname.php"); }); </script>
i made jquery plugin dynamicselect.js '$.fn.x =' adds jquery
$.fn.dynamicselect = function(trigger, action) { var dynamicselect = $(this); trigger.on('change', function() { if(trigger.val() > 0){ $.getjson(action, {searchval: $(this).val()}, function(html) { dynamicselect.html(html); }); } else{ dynamicselect.html(''); } }); };
i wrote server side code yii framework, won't should give idea of needs done.
public function actionvehiclesearch() { $searchval = $_request['searchval']; $vehicles = vehicle::model()->findall(" customerid ? ", array('%' . $searchval . '%')); $str = ''; foreach ($vehicles $vehicle) { $str .= '<option value="'. $vehicle->vid .'">'. $vehicle->vin .'</option>'; } echo cjson::encode($str); }
Comments
Post a Comment