I want to write java script validation for textbox contain only numeric values and if all the values are numeric then there is one button control will get enable or else disable.

<%@ Page Language="VB" AutoEventWireup="false" CodeFile="Default.aspx.vb" Inherits="_Default" %>

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">

<html xmlns="http://www.w3.org/1999/xhtml">
<head runat="server">
<title>Untitled Page</title>
<script type="text/javascript">
function valNumeric(evt)
{
var charCode;
charCode = (evt.which) ? evt.which : event.keyCode;
if (charCode >= 48 && charCode <= 57 || charCode== 8 || charCode == 118 || charCode == 120 || charCode == 99 )
{
return true;
}
else
{
return false;
}
}
function EnableButton()
{
document.getElementById("Button1").style.visibility ="visible";
}
function DisableButton()
{
document.getElementById("Button1").style.visibility ="hidden";
}
</script>
</head>
<body onload="return DisableButton()">
<form id="form1" runat="server ">
<div>

<asp:TextBox ID="TextBox1" onkeypress="if(valNumeric(event)==true){EnableButton()}else{ return false}" runat="server"></asp:TextBox>
<asp:Button ID="Button1" runat="server" Text="Button" />
</div>
</form>
</body>
</html>

No comments:

Post a Comment

Plz Share your comments...