jQuery drop down to fill second drop down and text field -


i want use jquery populate second select box, , text field. have second select box getting populated correctly when selection made in first. have not been able populate text field though.

the data retrieved mysql database. below code have working first select box make selection in second.

my jquery code:

<script> $(document).ready(function(){   $("#shipment").change(function() {     $("#vender").load("selection.php", $("#shipment"));   }).trigger("change"); }); </script> 

form fields relevant this:

<html> <label for="shipments">shipment: </label><select id="shipment" name="shipment_id"> <?php if(isset($shipment_selection)) { echo $shipment_selection; } ?> //echos options db. </select> <label for="vender">vender: </label><select id="vender" name="vender_id"></select> <label for="cost">cost: </label>><input type="text" id="cost" name="cost" value="" /> </html> 

php script gets data:

<?php include('../scripts/db_config.php');  if(isset($_post['shipment_id'])) {     if($_post['shipment_id'] == 1) {     $sql = 'select id vender_id, name vender_name venders'; //shows venders, when shipment none.     } else { $sql = 'select venders.id vender_id, venders.name vender_name, shipment.qty qty, shipment.cost cost shipments inner join venders on venders.id=shipments.vender_id shipments.id='.$_post['shipment_id']; //select vender associated specific shipment. } $stmt = $db->query($sql); $data = array();     while ($row = $stmt->fetch(pdo::fetch_assoc)) {     $data[] = $row;     //echo '<option value="'.$row['vender_id'].'">'.$row['vender_name'].'</option>'; //populates second select box.     } echo json_encode($data); } 

i secure php code better after working.

any suggestions on how selection in first select box populate second select box, , text field great.

apologies if formatting off; blind, not sure how looks on screen.

the file accessed .load() should return html dumped given element. have returning json, unknown reason. remove that, , uncomment line outputting options.

alternatively, instead of using .load(), use full ajax call , iterate through returned json insert options way.


Comments

Popular posts from this blog

Why does Ruby on Rails generate add a blank line to the end of a file? -

keyboard - Smiles and long press feature in Android -

node.js - Bad Request - node js ajax post -