jquery - How to fill three text fields by selecting from first drop down menu using MySql in PHP -
i working on website , in have put user details have user name , address , phone , zip code.
all details stored in mysql.
so, in form , if click on user name drop down menu, 3 other text fields automatically filled respective data.
some thing , if username selected of id 13, address , other fields may have this, [insert address field, name=id13]
something that, not sure how works.
note : want auto-populate other 3 fields knowing first option. other 3 options stored in same database first option
my code far
<!-- start presonal information --> <fieldset class="col-md-6"> <legend>shipper data :</legend> <!-- name --> <div class="form-group"> <label class="control-label" >shipper<span class="required-field"></span></label> <select type="text" name="shippername" id="shippername" class="form-control"> <option value="0">select</option> <?php $sql=mysql_query("select * customer"); while($row=mysql_fetch_array($sql)){ echo '<option value="'.$row['shippername'].'">'.$row['shippername'].'</option>'; } ?> </select> </div> <div class="row" > <div class="col-sm-6 form-group"> <label class="control-label">address<span class="required-field"></span></label> <input type="text" name="shipperaddress" id="shipperaddress"class="form-control" autocomplete="off" required> </div> <div class="col-sm-3 form-group"> <label class="control-label">phone</label> <input type="text" class="form-control" name="shipperphone" id="shipperphone" autocomplete="off" required> </div> <div class="col-sm-3 form-group"> <label class="control-label">pin code</i></label> <input type="text" name="shippercc" id="shippercc"class="form-control" maxlength="20" placeholder="" autocomplete="off" required> </div> </div>
check jfiddle in comment
//jquery
$('#shippername').change(function() { selectedoption = $('option:selected', this); $("#shipperaddress").val( selectedoption.data('address') ); $("#shipperphone").val( selectedoption.data('phone') ); $("#shippercc").val( selectedoption.data('zipcode') ); });
//php
<select name="shippername" id="shippername"> <option value="0">select</option> <?php $sql=mysql_query("select * customer"); while($row=mysql_fetch_array($sql)) { ?> <option value="<?php echo $row['shippername'];?>" data-address="<?php echo $row['shipperaddress'] ?>" data-phone="<?php echo $row['shipperphone'] ?>" data-zipcode="<?php echo $row['shippercc'] ?>"><?php echo $row['shippername'];?></option> <?php } ?> </select> <div class="row" > <div class="col-sm-6 form-group"> <label class="control-label">address<span class="required-field"></span></label> <input type="text" name="shipperaddress" id="shipperaddress"class="form-control" autocomplete="off" required> </div> <div class="col-sm-3 form-group"> <label class="control-label">phone</label> <input type="text" class="form-control" name="shipperphone" id="shipperphone" autocomplete="off" required> </div> <div class="col-sm-3 form-group"> <label class="control-label">pin code</i></label> <input type="text" name="shippercc" id="shippercc"class="form-control" maxlength="20" placeholder="" autocomplete="off" required> </div> </div>
Comments
Post a Comment