I have input
type which is span. And I want to calculate between two text. So I tried implementing like below. But the alert is always coming 0
function ValidateFormFTTX(ApproveRejectSave) {
var acceptedUG = parseInt($('#FEUGLEG_txtReadOnlyAccepted').text());
var TotalUG = parseInt($('#FEUGLEG_txtReadOnly').text());
var offerUG = parseInt($('#FEUGLEG_txt').val());
alert(offerUG);
var calculatedUG = (parseFloat(TotalUG) + parseFloat(offerUG).toFixed(4));
}
<td class="tdWidth disableField">
<span id="FEUGLEG_txtReadOnly" class="text-center"></span>
</td>
<td class="tdWidth disableField">
<span id="FEUGLEG_txtReadOnlyAccepted" class="text-center"></span>
</td>
<td class="tdWidth"><input id="FEUGLEG_txt" type="text" class="text-center" value="0" onkeypress="return isNumberKey(event, this);" maxlength="6" /></td>
4
Answers
Make sure that this script is executed after the DOM has fully loaded. You can wrap your code inside a document ready function like this:
Please try like below. change val() to value
You can use a number field instead of a text field. Also, you never called your
ValidateFormFTTX
function.Note: I added a jQuery debounce plugin to limit the number of times the validation is called upon input.
You are not executing ValidateFormFTTX, only the function
isNumberKey
which you did not provide.I recommend to not use inline event handlers.
Also you have the toFixed in the wrong place
Alternatively use
type="number"
on the fieldHere is working code