<html>
<body>
<label>
<input type="text" id="Semester Attended"/>
Semester
</label>
<br/><br/>
<input type="checkbox" name="Books" value="100" onchange ="TotalCost()"> Books $100 per Semester.<br>
<input type="checkbox" name="Tution" value="1000" onchange="TotalCost()">Tution $1000 per semester.<br>
<input type="checkbox" name="Room and Board" value= "750" onchange="TotalCost()"> Room and Board $750 per Semester. <br>
<input type ="reset" id= "reset"/>
<input type="submit" id="Submit"/>
</p>
</form>
</body>
</html>
<script>
function chkPhone(){
var x = document.getElementById("phone").value;
if (x==null || x=="")
{
alert("Phone number cannot be left blank");
return false;
}
if(isNaN(x)|| x.indexOf(" ")!=-1)
{
alert("Invalid phone number")
return false;
}
if (x.length > 10)
{
alert("Only 9 characters");
return false;
}
}
function chkSocial(){
var social = document.getElementById("social security").value;
if (social==null || social=="")
{
alert("social security cannot be left blank");
return false;
}
if(isNaN(social)|| social.indexOf(" ")!=-1)
{
alert("Invalid Social Security ");
return false;
}
if (social.length > 9)
{
alert("Enter only 9 characters for Social Security");
return false;
}
}
function chkisEmailCorrect() {
var re = /^\w+([\.-]?\w+)*@(((([a-z0-9]{2,})|([a-z0-9][-][a-z0-9]+))[\.][a-z0-9])|([a-z0-9]+[-]?))+[a-z0-9]+\.([a-z]{2}|(com|net|org|edu|int|mil|gov|arpa|biz|aero|name|coop|info|pro|museum))$/i;
if(re.test(document.getElementById("Email").value)) return true;
else {
alert("Email is incorrect!");
document.getElementById("Email").focus();
return false;
}
}
function chkisValidPostalCode() {
var re = /^\d{5}([\-]\d{4})?$/;
var nameValue=document.getElementById("address").value;
if(nameValue == '' || nameValue == null ){
alert('This field is Required');
document.getElementById("address").focus();
return false;
}
else if(!re.exec(nameValue)){
alert('Enter a valid postal code');
document.getElementById("address").focus();
return false;
}
else{
alert('Valid');
}
return true;
}
functionTotalCost
function chkName() {
var myName = document.getElementById("custName");
var pos = myName.value.search (
/^[A-Z][a-z]+, ?[A-Z][a-z]+, ?[A-Z]\.?$/);
if (pos !=0) {
alert("The name you entered (" + myName.value +") is not the correct form. \n" + "The correct form is: " + "last-name, first-name, middle-initial \n" +
"Please go back and fix your name");
return false;
}else
return true;
}
document.getElementById("phone").onchange = chkPhone;
document.getElementById("social security").onchange = chkSocial;
document.getElementById("Email").onchange = chkisEmailCorrect;
document.getElementById("address").onchange = chkisValidPostalCode;
document.getElementById("custName").onchange = chkName;
</script> |