Hello Sir,
Below is the code which I'm using to compare 2 textbox values on button click using JavaScript.
But here even if the value is less than the available points I'm getting a warring message like
Points scored must be less than or equal available points (Check 1)!
Please help me to resolve
<div>
<asp:TextBox ID="txt_name" class="form-control" placeholder="Enter Name" runat="server"></asp:TextBox>
<div class="form-group">
<label>
Available Points</label>
<asp:TextBox ID="txt_availablepoints" Text="70" class="form-control" placeholder="Enter Available Points"
runat="server" ReadOnly="true"></asp:TextBox>
</div>
<div class="form-group">
<label>
Points scored</label>
<asp:TextBox ID="txt_pointscored" class="form-control" placeholder="Enter Points scored"
runat="server"></asp:TextBox>
</div>
</div>
<asp:Button ID="btn_save" class="btn btn-info btn-wd" runat="server" Text="Save"
OnClick="btn_save_Click" OnClientClick="doWork1();return false;" />
<script type="text/javascript">
var counter = 0;
var atLeast = 1
function doWork1() {
var fv1 = document.getElementById('<%=txt_name.ClientID%>').value;
var fv4 = document.getElementById('<%=txt_pointscored.ClientID%>').value;
var fv25 = document.getElementById('<%=txt_availablepoints.ClientID%>').value;
var regex = /^[0-9.0-9]+$/;
if (fv1.length == "") {
swal("Validate", "Please enter name!", "error");
}
else if (fv4.length == "") {
swal("Validate", "Please enter Points scored(Check 1)!", "error");
}
else if (regex.test(fv4) == false) {
swal({
title: "Warning",
text: "Please enter only numerics in Points scored(Check 1) field",
type: "warning",
});
}
else if (fv4 > fv25) {
swal("Validate", "Points scored must be less than or equal available points(Check 1)!", "error");
}
else {
document.getElementById("btn_save").click();
}
}
</script>
Thanks in advance