I have a dropdown (transfertype) and a textbox (purchaseprice). When the dropdown (transfertype) is selected this decides what the textbox(purchaseprice) is allowed to do.
I am trying to figure out how when sale is selected to not allow alpha characters but if anything else is selected to then allow them again since it prefills based on the dropdown choice.
$(document).on('change', '#transfertype', function() {
var purchaseprice = $('#purchaseprice');
if($(this).val()==='' || $(this).val()==='Sale') {
purchaseprice.val('').prop('readOnly', false);
} else {
purchaseprice.val($(this).val()).prop('readOnly', true);
purchaseprice.valid();
}
calculateTotal();
});
<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.0/jquery.min.js"></script>
<label for="transfertype">Transfer type:</label>
<select name="transfertype" id="transfertype" required>
<option value="">Select Type</option>
<option value="Sale">Sale</option>
<option value="Gift">Gift</option>
<option value="Trade">Trade</option>
<option value="Repossession">Repossession</option>
<option value="Court Order">Court Order</option>
<option value="Inheritance">Inheritance</option>
<option value="Add Name">Add Name</option>
<option value="Remove Name">Remove Name</option>
<label for="purchaseprice" class="labelspace">Purchase price:</label>
<input type="text" name="purchaseprice" id="purchaseprice" required="yes"/>
Any help with this would be greatly appreciated.