Let me start by mentioning that lots of this code was inherited. I'm charged with making some things work and I'm certainly having issues with this.
The current page issues a form with numerous input fields that start out blank/empty. The php program reads a db table and from it fabricates a <select list showing the user the descriptions of the records. When it retrieves the records it also receives a charge_amount and a payment_amount. When the user selects one of the options the corresponding charge and payment amounts are to be plugged into the corresponding <input fields using javascript. Most of this works reasonable well but I'm stuck on this select issue.
The original code as you can see below simply places two extra fields on the input tab line which is not following HTML syntax. But, in some cases this logic works. The javascript function is show further down.
So my question is: What is the best method to use to pass this php contructed information to the js function so it can be plugged into the form field(s)? What's interesting is that there are TWO separate programs with these sections virtually identical. One of the programs works fine, the other doesn't work at all. And I receive no compile/syntax errors.
php snippet:
<select class="form-control m-b" name="description1" id="description1">
<option value=""> </option>
<? $CA = array(); while ($row11 = $q11->fetch()) { ?>
<option value="<?=$row11['description'];?>" charge_amount="<?=$row11["charge_amount"];?>" payment_amount="<?=$row11["payment_amount"];?>">
<?=$row11["description"]; $CA['$row11["description']=$row11["charge_amount"]; ?>
</option>
<? } ?>
<option value="Custom">Custom</option>
</select>
javascript function:
<!-- Custom Description handler -->
<script>
$(document).ready(function () {
$('#description1').change(
function() {
if (this.value == "Custom") {
$('#custDescTxt1').css("display", "");
$('#custDescLbl1').css("display", "");
} else {
if ($('#custDescTxt1').val().length == 0) {
$('#custDescTxt1').css("display", "none");
$('#custDescLbl1').css("display", "none");
}
}
$('#charge_amount1').val(this.options[this.selectedIndex].getAttribute("charge_amount"));
$('#payment_amount1').val(this.options[this.selectedIndex].getAttribute("payment_amount"));
}
);
});
</script>
Thanks for any guidance/suggestions.
The current page issues a form with numerous input fields that start out blank/empty. The php program reads a db table and from it fabricates a <select list showing the user the descriptions of the records. When it retrieves the records it also receives a charge_amount and a payment_amount. When the user selects one of the options the corresponding charge and payment amounts are to be plugged into the corresponding <input fields using javascript. Most of this works reasonable well but I'm stuck on this select issue.
The original code as you can see below simply places two extra fields on the input tab line which is not following HTML syntax. But, in some cases this logic works. The javascript function is show further down.
So my question is: What is the best method to use to pass this php contructed information to the js function so it can be plugged into the form field(s)? What's interesting is that there are TWO separate programs with these sections virtually identical. One of the programs works fine, the other doesn't work at all. And I receive no compile/syntax errors.
php snippet:
<select class="form-control m-b" name="description1" id="description1">
<option value=""> </option>
<? $CA = array(); while ($row11 = $q11->fetch()) { ?>
<option value="<?=$row11['description'];?>" charge_amount="<?=$row11["charge_amount"];?>" payment_amount="<?=$row11["payment_amount"];?>">
<?=$row11["description"]; $CA['$row11["description']=$row11["charge_amount"]; ?>
</option>
<? } ?>
<option value="Custom">Custom</option>
</select>
javascript function:
<!-- Custom Description handler -->
<script>
$(document).ready(function () {
$('#description1').change(
function() {
if (this.value == "Custom") {
$('#custDescTxt1').css("display", "");
$('#custDescLbl1').css("display", "");
} else {
if ($('#custDescTxt1').val().length == 0) {
$('#custDescTxt1').css("display", "none");
$('#custDescLbl1').css("display", "none");
}
}
$('#charge_amount1').val(this.options[this.selectedIndex].getAttribute("charge_amount"));
$('#payment_amount1').val(this.options[this.selectedIndex].getAttribute("payment_amount"));
}
);
});
</script>
Thanks for any guidance/suggestions.