|
-
October 16th, 2008, 02:53 AM
#3
Re: Javascript code for input validation & postback control
 Originally Posted by PeejAvery
Can you post the code with which you are working? It will give us better insight on what to suggest for you.
I know using validation controls, but want to try javascript
Code:
<%@ Page Language="vb" AutoEventWireup="false" CodeBehind="Default.aspx.vb" Inherits="HtmlEtc._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 validAge1(age)
{
if (isNaN(age) || age<10 || age>20)
{
alert("The age must be a number between 10 and 20");
document.getElementById('TextBox1').focus();
return false;
}
}
function validAge2(age)
{
if (isNaN(age) || age<20 || age>30)
{
alert("The age must be a number between 20 and 30");
document.getElementById('TextBox2').focus();
return false;
}
}
function validAge3(age)
{
if (isNaN(age) || age<30 || age>40)
{
alert("The age must be a number between 30 and 40");
document.getElementById('TextBox3').focus();
return false;
}
}
function validAge4(age)
{
if (isNaN(age) || age<40 || age>50)
{
alert("The age must be a number between 40 and 50");
document.getElementById('TextBox4').focus();
return false;
}
}
</script>
</head>
<body>
<form id="form1" runat="server">
<div>
<asp:TextBox ID="TextBox1" runat="server" onblur="validAge1(this.value)"></asp:TextBox>
<asp:TextBox ID="TextBox2" runat="server" onblur="validAge2(this.value)"></asp:TextBox>
<asp:TextBox ID="TextBox3" runat="server" onblur="validAge3this.value)"></asp:TextBox>
<asp:TextBox ID="TextBox4" runat="server" onblur="validAge4this.value)"></asp:TextBox>
</div>
<asp:Button ID="Button1" runat="server" Text="Button" />
</form>
</body>
</html>
Last edited by PeejAvery; October 16th, 2008 at 06:44 AM.
Reason: Added code tags.
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|