Click here to Skip to main content
15,894,410 members
Please Sign up or sign in to vote.
1.00/5 (1 vote)
See more:
Hi Everyone!
In my project I'm validating the value of a textbox using the javascript code below. This code is working on IE, but not any other browser. Can anybody on help me with this issue.

This is from the code behind file:
C#
protected void Page_Load(object sender, EventArgs e)
{
    txtInvNopr.Attributes.Add("onblur", "return validate(this.value)");
}

This is my javascript code:
JavaScript
function validate(content)
{
    if(isNaN(content)==true)
    {
        alert('Enter Only Numeric Value');
        return false;
    }
    else
        return true;
}


Thanks in advance!
Posted
Updated 6-Oct-11 1:21am
v3
Comments
Manfred Rudolf Bihy 6-Oct-11 7:22am    
Edit: Spelling, grammar and clarity. Added code blocks, tidied up indentation.
[no name] 6-Oct-11 7:31am    
Have you debugged? What part isn't working?

This example works by only using javascript. It runs absolutely perfect on IE 8/9, FireFox 6.0.2 and Chrome 12.xxxx.
HTML
<html>
<head>
<script type="text/javascript">
    function validate(content)
    {
        if(isNaN(content)==true)
        {
            alert('Enter Only Numeric Value');
            return false;
        }
        else
            return true;
    }
</script>
</head>
<body>
<h1>Get attribute test!</h1>
<input id="btnClientId" type="text" value="" name="Whatchamacallit" onblur="return validate(this.value);"/>
<input id="submitIt" type="button" value="Do it!"/>
</body>
</html>


It must be something else that is going wrong in your code. Please use FireBug to debug your pages javascript.

Regards,

—MRB
 
Share this answer
 
v2
Comments
ManavGuru 6-Oct-11 8:37am    
Thank For Suggestion
If you are still having trouble, you can so long use parseInt() which i know will work in all browsers (i.e. IE5):

JavaScript
function validate(content)
{
   if(!parseInt(content))
   {
      alert('Enter Only Numeric Value');
      return false;
   }
   else
      return true;
}


Goodluck,
Morgs
 
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