<!DOCTYPE html>
<html>
<head>
<title>Unit 2 - Q11</title>
<script type="text/javascript">
function valid()
{
var name=document.udetail.uname.value;
var age=document.udetail.uage.value;
var add=document.udetail.uadd.value;
var eid=document.udetail.ueid.value;
var atrate=eid.indexOf("@");
var dot=eid.lastIndexOf(".");
var cb1=document.udetail.uhobby1.checked;
var cb2=document.udetail.uhobby2.checked;
var cb3=document.udetail.uhobby3.checked;
var rb1=document.getElementById('ugender1').checked;
var rb2=document.getElementById('ugender2').checked;
var rb3=document.getElementById('ugender3').checked;
var country=document.getElementById('ucountry').value;
if(name=="")
document.getElementById('uname').innerHTML="Name is mandatory.";
else
document.getElementById('uname').innerHTML="";
if(age=="")
document.getElementById('uage').innerHTML="Age is mandatory.";
else
document.getElementById('uage').innerHTML="";
if(add=="")
document.getElementById('uadd').innerHTML="Address is mandatory."
else
document.getElementById('uadd').innerHTML="";
if(eid=="")
document.getElementById('ueid').innerHTML="Email Id is mandatory.";
else if (atrate<1 || dot<atrate+2 || dot+2>=eid.length)
document.getElementById('ueid').innerHTML="Invalid Email Id.";
else
document.getElementById('ueid').innerHTML="";
if(cb1==false && cb2==false && cb3==false)
document.getElementById('uhobby').innerHTML="Hobby is mandatory";
else
document.getElementById('uhobby').innerHTML="";
if(rb1==false && rb2==false && rb3==false)
document.getElementById('ugender').innerHTML="Gender is mandatory";
else
document.getElementById('ugender').innerHTML="";
if(country=='')
document.getElementById('fucountry').innerHTML="Country is mandatory";
else
document.getElementById('fucountry').innerHTML="";
}
</script>
</head>
<body>
<br>
<form name="udetail">
<table align="center">
<tr>
<td>
Name
</td>
<td>
- <input type="text" name="uname">
</td>
<td>
<font color="red" id="uname"></font>
</td>
</tr>
<tr>
<td>
Age
</td>
<td>
- <input type="text" name="uage">
</td>
<td>
<font color="red" id="uage"></font>
</td>
</tr>
<tr>
<td>
Address
</td>
<td>
- <textarea rows="5" cols="22" name="uadd"></textarea>
</td>
<td>
<font color="red" id="uadd"></font>
</td>
</tr>
<tr>
<td>
Email Id
</td>
<td>
- <input type="text" name="ueid">
</td>
<td>
<font color="red" id="ueid"></font>
</td>
</tr>
<tr>
<td>
Hobby
</td>
<td>
- Reading <input type="checkbox" name="uhobby1">
Music <input type="checkbox" name="uhobby2">
Gaming <input type="checkbox" name="uhobby3">
</td>
<td>
<font color="red" id="uhobby"></font>
</td>
</tr>
<tr>
<td>
Gender
</td>
<td>
- Male <input type="radio" name="ugender" id="ugender1">
Female <input type="radio" name="ugender" id="ugender2">
Not Specified <input type="radio" name="ugender" id="ugender3">
</td>
<td>
<font color="red" id="ugender"></font>
</td>
</tr>
<tr>
<td>
Country
</td>
<td>
- <select id="ucountry">
<option selected> </option>
<option>India</option>
<option>U.S.</option>
<option>Russia</option>
<option>China</option>
<option>Other</option>
</select>
</td>
<td>
<font color="red" id="fucountry"></font>
</td>
</tr>
</table>
<p align="center"><input type="button" value="Submit" onclick="valid()"></p>
</form>
</body>
</html>
Be the first to comment
You can use [html][/html], [css][/css], [php][/php] and more to embed the code. Urls are automatically hyperlinked. Line breaks and paragraphs are automatically generated.