Javascript Validation On .Aspx Page

Posted by Paraszalariya12 under JavaScript on 4/18/2013 | Points: 10 | Views : 1833 | Status : [Member] | Replies : 3
Any One Gays tell me how to create JavaScript require field validation on multiple text box.....???




Responses

Posted by: Satyapriyanayak on: 4/18/2013 [Member] [MVP] Silver | Points: 25

Up
0
Down
<head runat="server">
<title>Untitled Page</title>
<script type="text/javascript" language="javascript">
function Validate()
{
var UName=document.getElementById('TextBox_user_name');
var Password=document.getElementById('TextBox_password');
if((UName.value=='') || (Password.value==''))
{
alert('UserName or Password should not be blank');
return false;
}
else
{
return true;
}
}
</script>
</head>
<body>
<form id="form1" runat="server">
<div>
<asp:Label ID="lb1" runat="server" Font-Bold="True" ForeColor="#FF3300"></asp:Label><br />
<asp:Label ID="Label1" runat="server" Text="UserName" Font-Bold="True" Width="100px" BackColor="#FFFF66" ForeColor="#FF3300"></asp:Label>

<asp:TextBox ID="TextBox_user_name" runat="server" ForeColor="#993300" Width="100px"></asp:TextBox><br />
<asp:Label ID="Label2" runat="server" Text="Password" Font-Bold="True" Width="100px" BackColor="#FFFF66" ForeColor="#FF3300"></asp:Label>

<asp:TextBox ID="TextBox_password" runat="server" ForeColor="#CC6600" TextMode="Password" Width="100px"></asp:TextBox><br />

<asp:Button ID="btn_login" runat="server" Text="Login" Font-Bold="True"
BackColor="#CCFF99" OnClientClick="Validate()" onclick="btn_login_Click"
/><br />
</div>
</form>
</body>
</html>


If this post helps you mark it as answer
Thanks

Paraszalariya12, if this helps please login to Mark As Answer. | Alert Moderator

Posted by: Paraszalariya12 on: 4/18/2013 [Member] Starter | Points: 25

Up
0
Down
Thanks Satyapriyanayak but i want add require field validation on multiple text box so How to validate a textboxes using single javascript method.....???

Paraszalariya12, if this helps please login to Mark As Answer. | Alert Moderator

Posted by: Satyapriyanayak on: 4/28/2013 [Member] [MVP] Silver | Points: 25

Up
0
Down
<%@ Page Language="C#" AutoEventWireup="true" CodeBehind="WebForm2.aspx.cs" Inherits="Validate_Textbox_using_javascript.WebForm2" %>

<!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 validateThreeBoxes(boxID1, labelID1, boxID2, labelID2, boxID3, labelID3) {
if (document.getElementById(boxID1).value == "") {
document.getElementById(labelID1).style.visibility = "visible";
}
if (document.getElementById(boxID2).value == "") {
document.getElementById(labelID2).style.visibility = "visible";
}
if (document.getElementById(boxID3).value == "") {
document.getElementById(labelID3).style.visibility = "visible";
}
}
</script>
</head>
<body>
<form id="form1" runat="server">
<div>

<asp:TextBox ID="TextBox1" runat="server"></asp:TextBox>
<asp:Label ID="Label1" runat="server" Text="Text1 Should Not be Empty" style="visibility:hidden"></asp:Label>
</div>
<div>
<asp:TextBox ID="TextBox2" runat="server"></asp:TextBox>
<asp:Label ID="Label2" runat="server" Text="Text2 Should Not be Empty" style="visibility:hidden"></asp:Label>
</div>
<div>
<asp:TextBox ID="TextBox3" runat="server"></asp:TextBox>
<asp:Label ID="Label3" runat="server" Text="Text3 Should Not be Empty" style="visibility:hidden"></asp:Label>
<input type="button" id="Button1" runat="server" value="Button1" />
</div>
</form>
</body>
</html>



using System;
using System.Collections;
using System.Configuration;
using System.Data;
using System.Linq;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.HtmlControls;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Xml.Linq;

namespace Validate_Textbox_using_javascript
{
public partial class WebForm2 : System.Web.UI.Page
{
protected void Page_Load(object sender, EventArgs e)
{
string textbox1Id = TextBox1.ClientID;
string label1Id = Label1.ClientID;
string textbox2Id = TextBox2.ClientID;
string label2Id = Label2.ClientID;
string textbox3Id = TextBox3.ClientID;
string label3Id = Label3.ClientID;
Button1.Attributes.Add("onclick", "validateThreeBoxes('" + textbox1Id + "','" + label1Id + "','" + textbox2Id + "','" + label2Id + "','" + textbox3Id + "','" + label3Id + "');");
}
}
}


If this post helps you mark it as answer
Thanks

Paraszalariya12, if this helps please login to Mark As Answer. | Alert Moderator

Login to post response