Hello,
I hope that I can get an answer for this question.
I have a MYSQL table for charges which contains the following fields: ChargesID, ChargesTitle, OfficialFees and ProfessionalFees. What I need is to make a dropdown list which contain ChargesTitle and upon selection to autofill the OfficialFees and ProfessionalFees. I found the following jquery script and is working fine with a static data only. Any idea to change or update the script to work with php and dynamic data from MYSQL.
<select id="Charges">
<option value="">Please Select</option>
<option value="1" data-officialcharges="100" data-professionalcharges="30" >Option 1</option>
<option value="2" data-officialcharges="200" data-professionalcharges="40" >Option 2</option>
<option value="3" data-officialcharges="300" data-professionalcharges="60" >Option 3</option>
<option value="4" data-officialcharges="500" data-professionalcharges="30" >Option 4</option>
<option value="5" data-officialcharges="600" data-professionalcharges="20" >Option 5</option>
</select>
<div>
<label>Official Fees</label> <input type="text" name="Cofficialcharges" />
<label>Professional Fees</label> <input type="text" name="Cprofessionalcharges" />
</div>
<script type="text/javascript" src="../js/jquery-2.0.2.js"></script>
<script type="text/javascript">
$('#Charges').change(function() {
selectedOption = $('option:selected', this);
$('input[name=Cofficialcharges]').val( selectedOption.data('officialcharges') );
$('input[name=Cprofessionalcharges]').val( selectedOption.data('professionalcharges') );
});
</script>
Thank you.