Back to Scripts page
Click in the text area below, select all and copy to grab the script
Script listing:
<HTML> <HEAD> <TITLE>Car Picker</TITLE> <SCRIPT LANGUAGE=JAVASCRIPT TYPE="TEXT/JAVASCRIPT"> <!-- Hide script from older browsers function validEmail(email) { invalidChars = " /:,;" if (email == "") { // cannot be empty return false } for (i=0; i<invalidChars.length; i++) { // does it contain any invalid characters? badChar = invalidChars.charAt(i) if (email.indexOf(badChar,0) > -1) { return false } } atPos = email.indexOf("@",1) // there must be one "@" symbol if (atPos == -1) { return false } if (email.indexOf("@",atPos+1) != -1) { // and only one "@" symbol return false } periodPos = email.indexOf(".",atPos) if (periodPos == -1) { // and at least one "." after the "@" return false } if (periodPos+3 > email.length) { // must be at least 2 characters after the "." return false } return true } function isNum(passedVal) { // Is this a number? if (passedVal == "") { return false } for (i=0; i<passedVal.length; i++) { if (passedVal.charAt(i) < "0") { return false } if (passedVal.charAt(i) > "9") { return false } } return true } function validZip(inZip) { // Is this a valid Zip code? if (inZip == "") { return true } if (isNum(inZip)) { // Check if Zip is numeric return true } return false } function submitIt(carForm) { // make sure they enter a color colorChoice = carForm.color.selectedIndex if (carForm.color.options[colorChoice].value == "") { alert("You must pick a color") return false } // make sure they enter in a number of doors doorOption = -1 for (i=0; i<carForm.DoorCt.length; i++) { if (carForm.DoorCt[i].checked) { doorOption = i } } if (doorOption == -1) { alert("You must choose 2 or 4 door") return false } // can't have the sunroof with a four door if (carForm.DoorCt[doorOption].value == "fourDoor" && carForm.sunroof.checked) { alert("The sunroof is only available on the two door model") return false } // check to see if the email's valid if (!validEmail(carForm.emailAddr.value)) { alert("Invalid email address") carForm.emailAddr.focus() carForm.emailAddr.select() return false } if (carForm.zip.value == "" && carForm.dealerList.selectedIndex == -1) { alert("You must either enter a Zip code, or pick the dealer closest to you") carForm.zip.focus() return false } if (!validZip(carForm.zip.value)) { alert("That is an invalid Zip code") carForm.zip.focus() carForm.zip.select() return false } // If we made it to here, everything's valid, so return true return true } function doorSet(sunroofField) { if (sunroofField.checked) { for (i=0; i<document.myForm.DoorCt.length; i++) { if (document.myForm.DoorCt[i].value == "twoDoor") { document.myForm.DoorCt[i].checked = true } } } } // End hiding script --> </SCRIPT> </HEAD> <BODY BGCOLOR=WHITE> <H2 ALIGN=CENTER>Car Picker</H2> <FORM onSubmit="return submitIt(this)" ACTION="someAction.cgi" NAME="myForm"> <TABLE BORDER=0 CELLSPACING=8 CELLPADDING=8> <TR> <TD ALIGN=RIGHT> Email Address: </TD> <TD COLSPAN=2> <INPUT NAME="emailAddr" TYPE=TEXT SIZE=30> </TD> </TR> <TR> <TD ALIGN=RIGHT> Colors: </TD> <TD COLSPAN=2> <SELECT NAME="color"> <OPTION VALUE="" SELECTED>Choose a color <OPTION VALUE=RED>Red <OPTION VALUE=GREEN>Green <OPTION VALUE=BLUE>Blue </SELECT> </TD> </TR> <TR> <TD ALIGN=RIGHT> Options: </TD> <TD> <INPUT TYPE=CHECKBOX NAME="sunroof" VALUE=YES onClick="doorSet(this)">Sunroof (Two door only) </TD> <TD> <INPUT TYPE=CHECKBOX NAME="pSteering" VALUE=YES>Power Windows </TD> </TR> <TR> <TD ALIGN=RIGHT> Doors: </TD> <TD COLSPAN=2> <INPUT TYPE=RADIO VALUE="twoDoor" NAME="DoorCt">Two <INPUT TYPE=RADIO VALUE="fourDoor" NAME="DoorCt">Four </TD> </TR> <TR> <TD COLSPAN=3> Enter your Zip code or pick the dealer nearest you: <P>Zip: <INPUT NAME="zip" TYPE=TEXT SIZE=5 MAXLENGTH=5> <SELECT NAME="dealerList" SIZE=4> <OPTION>California--Lemon Grove <OPTION>California--Lomita <OPTION>California--Long Beach <OPTION>California--Los Alamitos <OPTION>California--Los Angeles </SELECT> <P><INPUT TYPE=SUBMIT VALUE="Submit"> <INPUT TYPE=RESET> </TD> </TR> </TABLE> </FORM> </BODY> </HTML>