Web Design

My First JavaScript homework

Dated: 3-Sep-2016

<html>
<head>

function froll()
{
var a=document.getElementById(“roll”).value;
if (a==””)
{
alert(“Please enter roll number”);
document.getElementById(“roll”).focus();
return;
}
var b = “^[0-9]*$”;
var c;
c = a.match(b);
if (c==null)
{
alert(“Please enter a valid roll number”);
document.getElementById(“roll”).focus();
return;

}

}
function fname()
{
var a=document.getElementById(“name”).value;
if (a==””)
{
alert(“Please enter name”);
document.getElementById(“name”).focus();
return;
}

var b = “^[a-zA-z]*$”;
var c;
c = a.match(b);
if (c==null)
{
alert(“Please enter a valid name”);
document.getElementById(“name”).focus();
return;
}
}
function fphone()
{
var a=document.getElementById(“phone”).value;
if (a==””)
{
alert(“Please enter phone”);
document.getElementById(“phone”).focus();
return;
}

var b = “^[0-9]*$”;
var c;
c = a.match(b);
if (c==null)
{
alert(“Please enter a valid phone number”);
document.getElementById(“phone”).focus();
return;
}
}
function fcom()
{
var a=document.getElementById(“com”).value;
if (a==””)
{
alert(“Please enter some comments”);
document.getElementById(“com”).focus();
return;
}

}

<title>TestPage</title>
</head>
<body OnLoad=”document.myform.roll.focus();”>
<form name = “myform”>

Roll No: <input type=”text” id=”roll” name=”roll” onfocusout=”froll()” />

<br/>
<br/>
Name: <input type=”text” id=”name” onfocusout = “fname()”/>

<br/>
<br/>
Phone No: <input type=”text” id=”phone” onfocusout = “fphone()”/>

<br/>
<br/>
Comments: <textarea id=”com” onfocusout = “fcom()”/></textarea>

<input type=”button” value=”Save”/>
</form>
</body>
</html>

 

Advertisements