Tuesday, February 14, 2012

Form Validation using JavaScript in ASP.Net

Program of form validation using JavaScript in ASP.Net

Write below code to validate your form using JavaScript

<%@ Page Language="C#" AutoEventWireup="true" CodeFile="javascript.aspx.cs" Inherits="javascript" %>

<!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 language=javascript>
     function check()
       // alert("Hello");
       var name=document.getElementById("name").value;
       var age=document.getElementById("age").value;
       if(name=="" || age=="")
         alert("Enter name and age");
    <form id="form1">
    Enter name:-<input id="name" type="text" /><br />
    Enter age:- <input id="age" type="text" />
    <input id="Submit1" type="submit" value="Save it" onclick="check()" />

No comments:

Post a Comment