<HTML> <!-- ARCHIVE by FORTUNECITY.ws --> <HEAD> <TITLE>JavaScript Object (Suzanne Stagel's JavaScript Assignment #5 Part I) </TITLE> <SCRIPT language="JavaScript"> <!-- //Begin hiding JavaScript code from non-enabled browsers //This script does not use any form validation library. All validation of form entries is //done in this script. See other version for example of use of library functions. var ageValid = false; //indicates if age entry is valid var emailValid = false; //indicates if email entry is valid var customer; function customerObject (name,email,age) { this.name = name; this.email = email; this.age = age; this.display=display; } // display // Parameters: None // Functionality: Displays attributes of the customerObject function display() { window.status = "Information you submitted is displayed!"; document.writeln("<BODY bgcolor='navyblue' text='yellow' link='pink' vlink='purple'> <center> <br> <div style="height:5px"></div> </center> " + "<H1>Information You Submitted<BR><BR></H1>" + "<H3><BR>Customer name: " + this.name + "<BR>" + "Customer email: " + this.email + "<BR>" + "Customer age: " + this.age + "<BR></H3>" + </BODY>"); document.close(); } function displayInfo() { customer.display(); } // submitInfo // Parameters: form // Functionality: Updates status bar function submitInfo(form) { window.status = "Information submitted!"; customer = new customerObject(form.name.value,form.email.value,form.age.value); customer.display(); } // validateAge // Parameters: age, minimumAge // Functionality: verifies that the age is greater than or equal to the minimumAge function validateAge(age,minimumAge) { if (age < minimumAge) { alert("You indicated you are " + age + " years old. " + "You must be " + minimumAge + " to use this site. Please visit us after you turn " + minimumAge + "."); ageValid = false; } else { ageValid = true; } } // validateEmail // Parameters: emailString // Functionality: verifies that the emailString is properly formed // (with "@" and "." in correct relative positions) function validateEmail(emailString) { var atCharacter = "@"; var dotCharacter = "."; var emailLength = emailString.length; var atPosition = -1; var dotPosition = -1; //Check that email address contains "@" symbol and not as first character atPosition = emailString.search(atCharacter); if (atPosition == -1 || atPosition == 0) { alert("The email address you entered is invalid. Please reenter."); emailValid = false; } else {//search for "." symbol dotPosition = -1; //Find dotCharacter in emailString (-1 if not contained in string) while (dotPosition < emailLength) { if (emailString.charAt(dotPosition) == dotCharacter) { break; } else if (dotPosition == (emailLength-1)) { dotPosition = -1; break; } else dotPosition++; } //end while //Check that email address contains "." (dotCharacter) and is not the character //immediately following the "@" (atCharacter) and is not last character in entry if ( (dotPosition <= 0) || (dotPosition <= (atPosition+1)) || (dotPosition == (emailLength-1)) ) { alert("The email address you entered is invalid. Please reenter."); emailValid = false; } else { emailValid = true; } } } //--> </SCRIPT> </HEAD> <BODY bgcolor="navyblue" text="yellow" link="pink" vlink="purple"><script> (function(i,s,o,g,r,a,m){i['GoogleAnalyticsObject']=r;i[r]=i[r]||function(){ (i[r].q=i[r].q||[]).push(arguments)},i[r].l=1*new Date();a=s.createElement(o), m=s.getElementsByTagName(o)[0];a.async=1;a.src=g;m.parentNode.insertBefore(a,m) })(window,document,'script','//www.google-analytics.com/analytics.js','ga'); ga('create', 'UA-47423994-1', 'fortunecity.ws'); ga('send', 'pageview'); </script> <center> <br> <div> <script language="javascript" type="text/javascript" src="http://ad.broadcaststation.net/ads/show_ad.php?width=728&height=90"></script> </div> </center> <CENTER><H1>JavaScript Object Example</H1></CENTER> <FORM name="demographicsForm"> <TABLE cols="100,100" bgcolor="#FFB6C1" align=center border=1 cellpadding=10> <TR bgcolor="#23238E"> <TD COLSPAN=2 align=center><B><FONT color="white">Demographic Info</FONT></B> </TD> </TR> <TR> <TD width=100><FONT color="blue">Name: </FONT></TD> <TD width=100><INPUT type="text" value="Name" name="name"></TD> </TR> <TR> <TD><FONT color="blue">Email: </FONT></TD> <TD><INPUT type="text" value="Email Address" name="email" onChange="validateEmail(this.value)"></TD> </TR> <TR> <TD><FONT color="blue">Age: </FONT></TD> <TD><INPUT type="text" value="Your Age" name="age" onChange="validateAge(this.value,18)"></TD> </TR> <TR> <TD COLSPAN=2 align=center><INPUT type="button" value="Submit Info" onClick="submitInfo(demographicsForm)"></TD> </TR> </TABLE> </FORM> </BODY> <!-- ARCHIVE by FORTUNECITY.ws --> <center> <div> <br> <script language="javascript" type="text/javascript" src="http://ad.broadcaststation.net/ads/show_ad.php?width=300&height=250&cache=0"></script> <script language="javascript" type="text/javascript" src="http://ad.broadcaststation.net/ads/show_ad.php?width=300&height=250"></script> </div> <br> <br> </center> </HTML>