Lab15
This commit is contained in:
		
							
								
								
									
										49
									
								
								Chapter ZIPs/JavaScript/ch7/ex_7_11.html
									
									
									
									
									
										Executable file
									
								
							
							
						
						
									
										49
									
								
								Chapter ZIPs/JavaScript/ch7/ex_7_11.html
									
									
									
									
									
										Executable file
									
								
							@@ -0,0 +1,49 @@
 | 
			
		||||
<html>
 | 
			
		||||
<head>
 | 
			
		||||
<title>Example 7.11</title>
 | 
			
		||||
<script>
 | 
			
		||||
function getInfo()
 | 
			
		||||
{
 | 
			
		||||
	var name = prompt("What's your name?");
 | 
			
		||||
	var email = prompt("What is your email address?");
 | 
			
		||||
	email = checkEmail(email);
 | 
			
		||||
	document.getElementById('first').innerHTML = name;
 | 
			
		||||
	document.getElementById('second').innerHTML = email;
 | 
			
		||||
}
 | 
			
		||||
function checkEmail(address)
 | 
			
		||||
{
 | 
			
		||||
    flag = true; var atSign = "@"; var address; var okSign = true;
 | 
			
		||||
	while (flag)
 | 
			
		||||
	{
 | 
			
		||||
		var numChars = address.length; 
 | 
			
		||||
		for( j = 1; j < (numChars -5); j++)  
 | 
			
		||||
		{
 | 
			
		||||
			if (address.charAt(j) == atSign)
 | 
			
		||||
			okSign = false; 
 | 
			
		||||
		}
 | 
			
		||||
		if ((address.charAt(numChars - 4) != ".") ||  (okSign == true))
 | 
			
		||||
		{
 | 
			
		||||
			alert("Not a valid email address");
 | 
			
		||||
			address = prompt('Enter a valid email address or enter "quit" to exit the program');
 | 
			
		||||
			if (address == "quit")
 | 
			
		||||
			{
 | 
			
		||||
				address = "unavailable";
 | 
			
		||||
				flag = false;
 | 
			
		||||
			}
 | 
			
		||||
		}
 | 
			
		||||
		else
 | 
			
		||||
			flag = false;
 | 
			
		||||
	}
 | 
			
		||||
	return address;
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
		
 | 
			
		||||
</script>
 | 
			
		||||
</head>
 | 
			
		||||
<body><table align="center" width = "70%"><tr><td><br />
 | 
			
		||||
<input type ="button" onclick="getInfo()" value = "Enter your information"><br />
 | 
			
		||||
<h3>Your name is: <span id = "first"> </span></h3>
 | 
			
		||||
<h3>Your email address is: <span id = "second"> </span></h3>
 | 
			
		||||
</td></tr></table>
 | 
			
		||||
</body>
 | 
			
		||||
</html>
 | 
			
		||||
		Reference in New Issue
	
	Block a user