.NET Tutorials, Forums, Interview Questions And Answers
Welcome :Guest
 
Sign In
Register
 
Win Surprise Gifts!!!
Congratulations!!!


Top 5 Contributors of the Month
david stephan

Home >> Forum >> C# >> Post New QuestionBookmark and Share Subscribe to Forum

Javascript

Posted By: Karthikeyan Anbarasan     Posted Date: December 30, 2010    Points:2   Category :C#
How to make a text box to accept only numeric using javascript in C# based code

Responses
Author: Gautam Kanaujia             
Posted Date: December 31, 2010     Points: 5   


Add the handler to the TextBox:
TextBox1.Attributes.Add("onkeydown", "JavaScript:return isNumericKeyStroke();");

function isNumericKeyStroke()
{ var returnValue = false;
var keyCode = (window.event.which) ? window.event.which : window.event.keyCode;
if ( ((keyCode >= 48) && (keyCode <= 57))
|| // All numerics (keyCode == 8) || // Backspace (keyCode == 13) ) // Carriage Return returnValue = true;
if ( window.event.returnValue ) window.event.returnValue = returnValue;
return returnValue;}




Post Reply

You must Sign In To post reply
 
 
Find more Forum Questions on C#, ASP.Net, Vb.Net, SQL Server and more Here
Quick Links For Forum Categories:
ASP.NetWindows Application  .NET Framework  C#  VB.Net  ADO.Net  
Sql Server  SharePoint  OOPs  SilverlightIISJQuery
JavaScript/VBScriptBiztalkWPFPatten/PracticesWCFOthers
www.DotNetSpark.comUnAnsweredAll

Hall of Fame    Twitter   Terms of Service    Privacy Policy    Contact Us    Archives   Tell A Friend