Pages

Sunday, November 10, 2013

Program 2 (a)

2  a)

 Develop and demonstrate, using Javascript script, a XHTML document that collects the USN ( the valid format is: A digit from 1 to 4 followed by two upper-case characters followed by two digits followed by two upper-case characters followed by three digits; no embedded spaces allowed) of the user.
Event handler must be included for the form element that collects this information to validate the input. Messages in the alert windows must be produced when errors are detected


<html>
<head><title> usn </title>
<body>

<script>
function chkusn()
{
var str=document.getElementById("usn");
var result=str.value.search(/^[1-4]{1}[A-Z]{2}\d{2}[A-Z]{2}\d{3}$/);
if(result!=0)
{
alert("Entered USN  ("+str.value+")  is not in the correct form \n\n"+"\tThe correct path is 1ST10IS039\n\n"+"\t Please press reset button to re-enter your USN");
}
else
{
alert ("Entered USN ("+str.value+") is in correct form \n");
}
}
</script>

<center>
<h3>STUDENT    INFORMATION </h3>    

<form name="my form">
<p> <bold>ENTER YOUR USN</bold> </p>
<input type="text" id="usn" />
<br/><br/>
<input type="button" onclick="chkusn()" value="submit"/>
<input type="reset" value="reset"/>
</center>
</br>
</form>

</body>  
</html>


No comments:

Post a Comment