ASP & JavaScript
-
Hi, I have a few textbox on my form and would like to validate it through Java script. I know there is RequiredFieldValidator in asp.net but I would like to do that by Javascript. this is my code
<%@ Page Language="C#" AutoEventWireup="true" CodeBehind="Register.aspx.cs" Inherits="WebApplication1.Presentation.Register" %>
<!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></title>
<script language= "javascript" type="text/javascript"></script><style type="text/css"> .style1 { width: 100%; } .style2 { } .style3 { width: 153px; height: 17px; } .style5 { width: 151px; } .style6 { width: 91px; } .style7 { height: 23px; } .style8 { height: 26px; } .style9 { height: 25px; } .style10 { width: 151px; height: 23px; } .style11 { width: 91px; height: 23px; } </style> <script language="javascript" type="text/javascript">
// <![CDATA[
function StId\_txt\_onclick() { }
// ]]>
</script>
</head>
<body>
<form id="form1" runat="server">
<div><table class="style1"> <tr> <td colspan="4" class="style7"> <asp:Label ID="PrsnInfo\_lbl" runat="server" Text="Personal Information"></asp:Label> </td> </tr> <tr> <td class="style9"> <asp:Label ID="StId\_lbl" runat="server" Text="Student ID" Font-Names="Arial" Font-Size="Smaller"></asp:Label> </td> <td class="style9" colspan="3"> <input id="StId\_txt" runat="server" style="border: 0.3px inset #000000; height: 20px; width: 137px;" type="text" /> <asp:RequiredFieldValidator ID="Required
-
Hi, I have a few textbox on my form and would like to validate it through Java script. I know there is RequiredFieldValidator in asp.net but I would like to do that by Javascript. this is my code
<%@ Page Language="C#" AutoEventWireup="true" CodeBehind="Register.aspx.cs" Inherits="WebApplication1.Presentation.Register" %>
<!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></title>
<script language= "javascript" type="text/javascript"></script><style type="text/css"> .style1 { width: 100%; } .style2 { } .style3 { width: 153px; height: 17px; } .style5 { width: 151px; } .style6 { width: 91px; } .style7 { height: 23px; } .style8 { height: 26px; } .style9 { height: 25px; } .style10 { width: 151px; height: 23px; } .style11 { width: 91px; height: 23px; } </style> <script language="javascript" type="text/javascript">
// <![CDATA[
function StId\_txt\_onclick() { }
// ]]>
</script>
</head>
<body>
<form id="form1" runat="server">
<div><table class="style1"> <tr> <td colspan="4" class="style7"> <asp:Label ID="PrsnInfo\_lbl" runat="server" Text="Personal Information"></asp:Label> </td> </tr> <tr> <td class="style9"> <asp:Label ID="StId\_lbl" runat="server" Text="Student ID" Font-Names="Arial" Font-Size="Smaller"></asp:Label> </td> <td class="style9" colspan="3"> <input id="StId\_txt" runat="server" style="border: 0.3px inset #000000; height: 20px; width: 137px;" type="text" /> <asp:RequiredFieldValidator ID="Required
FWIW: While client-side validation may improve the user experience, you should always have validation on the server-side just to be safe. :)
Luc Pattyn [Forum Guidelines] [My Articles] Nil Volentibus Arduum
Please use <PRE> tags for code snippets, they preserve indentation, improve readability, and make me actually look at the code.
-
Hi, I have a few textbox on my form and would like to validate it through Java script. I know there is RequiredFieldValidator in asp.net but I would like to do that by Javascript. this is my code
<%@ Page Language="C#" AutoEventWireup="true" CodeBehind="Register.aspx.cs" Inherits="WebApplication1.Presentation.Register" %>
<!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></title>
<script language= "javascript" type="text/javascript"></script><style type="text/css"> .style1 { width: 100%; } .style2 { } .style3 { width: 153px; height: 17px; } .style5 { width: 151px; } .style6 { width: 91px; } .style7 { height: 23px; } .style8 { height: 26px; } .style9 { height: 25px; } .style10 { width: 151px; height: 23px; } .style11 { width: 91px; height: 23px; } </style> <script language="javascript" type="text/javascript">
// <![CDATA[
function StId\_txt\_onclick() { }
// ]]>
</script>
</head>
<body>
<form id="form1" runat="server">
<div><table class="style1"> <tr> <td colspan="4" class="style7"> <asp:Label ID="PrsnInfo\_lbl" runat="server" Text="Personal Information"></asp:Label> </td> </tr> <tr> <td class="style9"> <asp:Label ID="StId\_lbl" runat="server" Text="Student ID" Font-Names="Arial" Font-Size="Smaller"></asp:Label> </td> <td class="style9" colspan="3"> <input id="StId\_txt" runat="server" style="border: 0.3px inset #000000; height: 20px; width: 137px;" type="text" /> <asp:RequiredFieldValidator ID="Required
I agree that server side validation is safe. still if you wish to proceed then please find below example to validate textbox. var txtValue = document.getElementById(<"%txt1.ClientID%">).value; if(txtValue==null || txtValue='') { alert('Please enter value in textbox.'); //message should be depends on requirement. return false; } Let me know still if you have any doubts.
Regards Keyur Satyadev