javascript - how to retrieve data into textfields when i select an option in droplist -


<strong>type of party</strong> <select name="p_name">     <?php          $sql = mysqli_query($con, "select * party");         while ($row = $sql->fetch_array()){              echo '<option value="'.$row['type_party'].'">'.$row['type_party'].'</option>';           }     ?>     </select>   <p>     <strong>max no. of children</strong>     <input type="text" id="txt" name="nocc" placeholder="type children" required="required" /> </p> 

i want retrieve data in textfield corresponding data of option select in droplist. in table: have id, type_party, capacity, , want receive capacity in textfield when select type_party in dropdownlist. please me out.

given, use jquery, achieved storing capacity in data attribute.

<strong>type of party</strong> <select name="p_name" > <?php  $sql = mysqli_query($con, "select * party"); while ($row = $sql->fetch_array()){  echo '<option value="'.$row['type_party'].'" data-capacity="' . $row['capacity'] . '">'.$row['type_party'].'</option>';   } ?> </select>   <p> <strong>max no. of children</strong> <input type="text" id="txt" name="nocc" placeholder="type children" required="required" /> </p> 

with following javascript code

$('select[name="p_name"]').on('change', function() {     $('#txt').val($(':selected', this).data('capacity')); }); 

Comments

Popular posts from this blog

php - Permission denied. Laravel linux server -

google bigquery - Delta between query execution time and Java query call to finish -

python - Pandas two dataframes multiplication? -