How do I change the value of a hidden input field to be what the user types in the <input>?
Input Fields
<input
type="number"
id="custom-donation-amount"
placeholder="50.00" onfocus="(this.value == '50.00') && (this.value = '')"
onblur="(this.value == '') && (this.value = '50.00')"
/>
and the hidden one:
<input id="paypal_value" type="hidden" name="amount" value="">
Jquery
<script type="text/javascript">
if (!$('#custom-donation-amount').val()) {
($("#paypal_value").val("50.00")) && ($("#custom-donation-amount").val("50.00"));
}
else $("#custom-donation-amount").change(function(){
$("#paypal_value").val($("#custom-donation-amount").val())
});
(this.value == '50.00') && (this.value = '')is supposed to mean sincethis.value = ''will always be true (you are assigning a value with this, not comparing a value).if (this.value == '50.00') {this.value = ''}