Click here to Skip to main content
15,886,782 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
My problem is that my javascript funtion to check validation that obtained marks should not be greater than max marks is not working for large no like 1000

What I have tried:

My Javascript funtion
C#
function Gmarks() {

                                var txtGMarksObtain =  parseInt(document.getElementById("<%=txtGMarksObtain.ClientID%>").value);
                                var txtGMaxMarks = parseInt(document.getElementById("<%=txtGMaxMarks.ClientID%>").value);

                                if (txtGMarksObtain > txtGMaxMarks) {
                                    alert("Graduation Obatined Marks must be less than Max Marks..");
                                    txtGMarksObtain.focus();
                                    return false;
                                }

                                return true;

                            }

 <asp:TextBox ID="txtGMarksObtain" onkeypress="return Gmarks()" runat="server" MaxLength="4"  />
Posted
Updated 25-May-17 0:50am
v2
Comments
CPallini 25-May-17 3:28am    
Could you please give us an example of the misbehaviour?
Rohit kumar6210 25-May-17 4:00am    
when max marks is 1000 and entered obtained marks is more than 1000 it's doesn't work...
Bohdan Stupak 25-May-17 3:29am    
how do you treat numbers greater than 1000 in your app? I mean depending on the culture it might be 1 000 or 1,000. And whereas parseInt("1000") is actually 1000, parseInt("1 000") or parseInt("1,000") is actually 1.
Rohit kumar6210 25-May-17 4:00am    
when max marks is 1000 and entered obtained marks is more than 1000 it's doesn't work...
Richard MacCutchan 25-May-17 3:29am    
What are the actual values in the case where you think it does not work?

1 solution

I have checked your code,
can you check with alert above if condition :
"alert("txtGMarksObtain" + txtGMarksObtain + " and " + "txtGMaxMarks" + txtGMaxMarks);"


you got the value or not, i think code is working fine but just check in console you got the any error.
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900