Hello and welcome to our community! Is this your first visit?
Register
Enjoy an ad free experience by logging in. Not a member yet? Register.
Page 1 of 2 12 LastLast
Results 1 to 15 of 16
  1. #1
    Regular Coder
    Join Date
    Dec 2002
    Location
    Phoenix, Arizona, USA
    Posts
    148
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Post Advanced Form Validation

    Advanced Form Validation Example

    Part I of 3

    Code:
    <!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN">
    
    <html>
    <head>
        <title>Advanced Form Validation Script v6.2: Commented</title>
        <meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1">
    
    <!-- Start Javascript -->
    <script language="JavaScript">
    <!-- Hide Me
    
    /*
        Advanced Form Validation Script v6.2
        (C) 2000, 2001 Phoenix Now Inc.
    
        Reproduction of this script is Prohibited
        Unless this comment remains
    
        Visit us Online at:
        http://www.phxnow.com
    
        Contact Us at:
        info@phxnow.com
    	
    	### NOTE ###
    	BEFORE you start to RIP this script appart, make a copy of it.
    	
    	I have Commented the Areas you can change
    	and how to change them correctly. The following
    	denotes the special comment area of information.
    	
    	## Special Comment Area ##
    	
    	Set the title of your page, to what you want to be seen in the email.
    	The document title is used for the email title, and the subThanks window
    	title.
    */
    
    // Focus the first form element
    function focusIt()  {
    	window.document.forms[0].elements[0].focus();
    }
    
    // Redirect the user to a thank you page
    function redirectIt() {
    	window.document.location.replace("thanks.htm"); // ## Change the page name and or location to your thank you page. ##
    }
    
    // Reload the current page.
    function reloadIt()    {
        window.document.location.reload()
    }
    
    // Build Thank you window based on form elements.
    function subThanks() {
    	/*
    	##
    		The subThanks page displays information to the sender about what has been sent.
    		This page also gives them a chance to print a hard copy for there records.
    		If you wish to change any of the format of this window, becareful, table information is
    		set in three areas. The first area is in the Variables below, col, cot, coz and brk.
    		The second area is in the newWin.document.write lines. this area is the top portion of the new
    		window. It displays a thank you, displays ths user email, the form name, last name and first name,
    		as well as the top print button. The third and final area, is what is used to generate the rest 
    		of the table. You should not have to touch any of this, as all the cell formatting is done in the
    		top Variables.
    		
    		If you change the name value of your First Name, Last Name and Email address, make sure to update
    		this information  here in section two as well. reqRequestor_First_Name, reqRequestor_Last_Name
    		reqRequestor_Email are all called in the second section.
    	##
    	*/
    	var bg = 0;
    	var daHeight = screen.height / 2;
    	var daWidth = screen.width / 2;
    	var topPos = 0;
    	var leftPos = 0;
    	if (screen) {
    		topPos = daHeight-200;
    		leftPos = daWidth-250;
    	}
    	var form = window.document.forms[0];
    	var doct = window.document.title.toString();
    	var now = new Date();
    	newWin = window.open('','thanks','scrollbars=1,width=570,height=450,left='+leftPos+',top='+topPos+'');
    	newWin.document.writeln("<html><head><title>" + doct + "<\/title><link rel='STYLESHEET' type='text/css' href='main.css'><\/head><body bgcolor='#ffffff' text='#000000'>");
    	newWin.document.writeln("<h1>Thank You!<\/h1>");
    	newWin.document.writeln(form.reqRequestor_First_Name.value + " " + form.reqRequestor_Last_Name.value + ", thank you for completing the " + doct + "<p>");
    	newWin.document.writeln("A Copy of the results below have been emailed to you at <a href='mailto:" + form.reqRequestor_Email.value + "'?subject='" + doct + "' class='mroller' title='Your Email Address'>" + form.reqRequestor_Email.value + "</a>. We sugguest that you print a copy for your records as well." + "<p>");
    	newWin.document.writeln("<form class='forma'><input type='button' name='print' class='forma' value='Print Doc' title='Print Document' onClick='window.print()'><p>");
    	newWin.document.writeln("<table width='510' cellpadding='1' cellspacing='3' border='0' title='Form Information'>");
    	newWin.document.writeln("<tr><td colspan='2' bgcolor='#bebebe' class='copy'>" + doct + " Submitted on " + now.toLocaleString() + "<\/td><\/tr>");
    	/*
    	##
    		The below section is the third section for generating the subThanks window.
    		This section loops over the entire form, and then writes the information to
    		the new subThanks window. There are some rules to what is shown and what is
    		not shown in the subThanks window. Everything else is printed to the new window
    		accept the following.
    		
    			1. Checkboxes and Radio buttons that are not checked
    			2. Button Types
    			3. Hidden fields
    			4. hidden form objects whos name ='s "=================================================="
    			   This is used for a break, when the loop finds an element with the above equal signs, the
    			   Variable brk is written which is equal to "<tr><td colspan=2 bgcolor=#e6e6e6>&nbsp;<\/td><\/tr>";
    			   This break is definded above at line 89
    			5. The Table is closed when the loop hits a submit or reset button.
    	##
    	*/

  • #2
    Regular Coder
    Join Date
    Dec 2002
    Location
    Phoenix, Arizona, USA
    Posts
    148
    Thanks
    0
    Thanked 0 Times in 0 Posts
    Part II of III

    Code:
    	for (i=0; i<form.length; i++) {
    		tdc = (bg % 2==0)?"#eeeeee":"#e0e0e0"
    		bg++
    		var col = "<tr bgcolor=" + tdc + "><td width='220' align='right'>";
    		var cot = ":<\/td><td width='280'>";
    		var coz = "<\/td><\/tr>";
    		var brk = "<tr bgcolor='#bebebe'><td colspan='2'><img src='spcr.gif' width='5' height='3' border='0'><\/td><\/tr>";
    		var formObj = form.elements[i];
    		var underScore = /_/g;
    		if (formObj.name.substring(0,3) == "req") {
    			var theName = formObj.name.substring(3).toString();
    			var shortName = theName.replace(underScore," ");
    		}
    		else {
    			var theName = formObj.name.toString();
    			var shortName = theName.replace(underScore," ");
    		}
    		if (formObj.type == "submit" || formObj.type == "reset") {
    			newWin.document.writeln("<\/td><\/tr><\/table>");
    			newWin.document.writeln("<p><form class=forma><input type='button' name='print' class='forma' value='Print Doc' title='Print Document' onClick='window.print()'><form class=forma><input type=button class=forma name=close value='Close' title='Close Document' onClick='window.close()'><\/form>");
    			newWin.document.writeln("<\/body><\/html>");
    			newWin.document.close();
    			return true;
    		}
    		else {
    			if ((formObj.type == "checkbox" || formObj.type == "radio") && formObj.checked == false) {
    				newWin.document.write("");
    			}
    			else if (formObj.type == "button") {
    				newWin.document.write("");
    			}
    			else if (formObj.type.toString().charAt(0) == "s") {
    				newWin.document.writeln(col + "<b>" + shortName + "</b>" + cot + formObj.options[formObj.selectedIndex].value + coz);
    			}
    			else if (formObj.name == "==================================================") {
    				newWin.document.writeln(brk);
    			}
    			else if (formObj.type == "hidden") {
    				newWin.document.write("");
    			}
    			else {
    				newWin.document.writeln(col + "<b>" + shortName + "</b>" + cot + formObj.value + coz);
    			}
    		}
    	}
    }
    
    // Form Element Validation
    /*
    ##
    	The Validation checks just about every type of field accept buttons and hidden fields.
    	Any field name that has an req in it like the following...
    		<input type="Text" name="reqFirst_Name">
    	Will get passed through the validation process. Text objects like Text, Textarea, Password, and File
    	are also checked for spaces. The user can enter as many spaces as they want, the field will not pass
    	unless valid data is entered in the fields. Spaces can be used, as long as there are other characters
    	like A-Z, 0-9, Special characters, etc...
    	
    	The Validation process has three steps, Text Based elements, Select Elements and Checked Elements.
    	Each has there own alert message, these can be changed, and have been commentd as such...
    	The checkbox validation is a bit strange, it does not start by looking for a checkbox. It looks
    	for elements that have the same name, and then access the array of the name to see which is checked
    	and which is not checked. Becarful about nameing other elements the same name.
    ##
    */
    function checkForm(which) {
    	var pass = true;
    	var form = window.document.forms[0];;
    	if (form.elements) {
    		for (i=0; i<which.length; i++) {
    			var formObj = which.elements[i];
    			if (formObj.name.substring(0,3)=="req") {
    				var underScore = /_/g;
    				var theName = formObj.name.substring(3).toString();
    				var shortName = theName.replace(underScore," ");
    				if (((formObj.type == "text" || formObj.type == "textarea" || formObj.type == "password" || formObj.type == "file") && formObj.value == ' ' < -1)) {
    					pass = false;
    					var ent1 = "" + formObj.value;
    					if (ent1 && ent1.length > 0) {
    						ent1 = "" + eval(ent1);
    						// ## Text Area Alert Message - No Spaces ##
    						alert("##### REQUIRED FIELD ERROR ##### \n" + shortName + "\n\nMust contain information other then Space(s).\nPlease only use valid information for this field.");
    						formObj.value='';
    						formObj.focus();
    						break;
    					}
    					else {
    						// ## Text Area Alert Message - Needs Data ##
    						alert("##### REQUIRED FIELD ERROR ##### \n" + shortName + "\n\nField has not been completed. Please make\nsure that the field contains valid information.");
    						formObj.focus();
    						break;
    					}
    				}
    				else if (formObj.type.toString().charAt(0) == "s" && formObj.selectedIndex == 0) {
    					pass = false;
    					// ## Select Windows Alert Message ##
    					alert("##### REQUIRED FIELD ERROR ##### \n" + shortName + "\n\nMust have a valid selection, please make\nyour selection now.");
    					formObj.focus();
    					break;
    				}
    				else if (!form.elements[formObj.name].name && formObj.type == "checkbox" || !form.elements[formObj.name].name && formObj.type == "radio" ) {
    					notChecked = true
    					var nameObj = form.elements[formObj.name];
    					for (j=0; j<nameObj.length; j++) {
    						if (nameObj[j].checked == true) {
    							notChecked = false
    						}
    					}
    					if (notChecked) { 
    						pass=false;
    						// ## Checkbox and Radio button Alert Message ##
    						alert("##### REQUIRED FIELD ERROR ##### \n" + shortName + "\n\nMust have a valid checked selection,\nplease make your checked selection now.");
    						break;
    					}
    				}
    			}
    		}
    	}
    	if (pass) {
    		// ## Form Confirmation Message to send the form ##
    		if (confirm("########## BEFORE YOU CONTINUE ########## \n Please make sure you have filled out the form correctly. \n\n If you would like to continue, click OK, if you would like \n to make any changes to your form, please click on Cancel.")) {
    			form.action = form.sentaddrs.value;
    			setTimeout('subThanks()', 2000);
    			 // ## This confirmation asks the user if they want to fill out the form again, or go to another page. ##
    			if (confirm("################# CONFIRM ACTION ################# \n Would you like to Fill out another request after this one has been sent?  \n\n Please Click OK for YES or Cancel for NO")) {
    				setTimeout('reloadIt()', 6000);
    			}
    			else {
    				setTimeout('redirectIt()', 6000);
    			}
    			return true;
    		}
    		// ## This extra alert message can be removed if you wish., just remove the else statement ##
    		else {
    			alert("Form Submission Canceled!");
    			return false;
    		}
    		// ## Stop Else Statement for Alert Message ##
    		return true;
    	}
    	return pass;
    }
    
    // Confirm the form Reset
    function confirmReset()	{
    		 // ## Confirms form reset ##
    	if (confirm("########## WARNING ########## \n This action will clear all data in the form. \n \n If you wish to Reset the Form, click on OK. \n If you wish to Cancel, click on CANCEL.")) {
    		alert("The Form will now be Reset!");
    		focusIt();
    		return true;
    	}
    	// ## This extra alert message can be removed if you wish., just remove the else statement ##
    	else {
    		alert("Form Reset Cancled!");
    		return false;
    	}
    	// ## Stop Else Statement for Alert Message ##
    }
    
    // Check for a valid Email address
    function validEmail() {
    	var EmailOk  = true;
    	var temp     = window.document.forms[0].reqRequestor_Email; // ## If you change the field name of the Requestor, you will need to update here as well. ##
    	var atsym    = temp.value.indexOf('@');
    	var period   = temp.value.lastIndexOf('.');
    	var space    = temp.value.indexOf(' ');
    	var length   = temp.value.length - 1;
    	if ((atsym < 1) || (period <= atsym+1) || (period == length ) || (space  != -1)) {  
    		var emailok = false;
    		// ## You can change your Valid Email alert message here ##
    		alert('###### VALID EMAIL REQUIRED ###### \n Please enter a Valid Email Address! \n\n An example of a Valid Email Address would be \n\n userid@email.sps.mot.com \n')
    		temp.value='';
    		temp.focus();
    	}
    	return emailok
    }
    
    // Add and Remove users to send this form to
    /*
    ##
    	The following script was a little tough as it has a lot of string handling.
    	I have commented each line to help you understand it and me to remember how I did it. :-)
    ##
    */

  • #3
    Regular Coder
    Join Date
    Dec 2002
    Location
    Phoenix, Arizona, USA
    Posts
    148
    Thanks
    0
    Thanked 0 Times in 0 Posts
    Part III of III

    Code:
    function addEmail()	{
    	var form		= window.document.forms[0];						// Sets the Variable Form
    	var addr        = form.reqAddresses;							// Sets the Variable of the reqAddresses - If you change this element name, change the name here as well.
    	var sale        = form.reqCoEmail;								// Sets the Variable for the Drop List of users to email - If you change this element name, change the name here as well.
    	var strn        = sale.options[sale.selectedIndex].value + " "; // Sets the Variable for the selected name and adds a space to the end of it. The space is REQUIRED DO NOT REMOVE IT.
    	var addval      = addr.value;									// Sets the Variable for the Address Value
    	var dasplit     = addval.split(strn);							// Sets the Variable of the split. The split makes an array of strn or the Selected user to email, this is used for removing a user if they are not wanted in the email list.
    	var dastring    = addval = dasplit.toString();					// Sets the Varialbe to a string so I can remove the commas
    	var davalue     = dastring.replace(',','');						// Sets the Varialbe to remove the commas
    	var start       = strn.indexOf(-1);								// Sets the Variable for a start position
    	var stop        = strn.indexOf('@');							// Sets the Variable for a stop position
    	var user        = strn.substring(start, stop).toUpperCase();	// Sets the Variable of the start and stop, then puts it to uppercase
    	var sel			= window.document.forms[0].reqCoEmail;			// Sets the Variable sel for selected index.
    	if(sel.selectedIndex != 0) {
    		pos = 0
    		num = -1
    		i   = -1
    		while (pos != -1) {
    			pos = addr.value.indexOf(strn ,i+1)
    			num += 1
    			i   = pos
    		}
    		if (num != 0) {
    			// ## Remove User Confirm Text ##
    			if (confirm("######### REMOVE USER CONFIRMATION ######### \n\n You are about to REMOVE user " + user + " from the list of users \n to email. Continue?")) {
    				alert("User " + user + " will now be REMOVED!");
    				addr.value = davalue
    				return true;
    			}
    			// ## This extra alert message can be removed if you wish., just remove the else statement ##
    			else {
    				alert("User " + user + " will not be REMOVED!");
    				return false;
    			}
    			// ## Stop Else Statement for Alert Message ##
    		}
    		else {
    			// ## Add User Confirm Text ##
    			if (confirm("######### ADD USER CONFIRMATION ######### \n\n You are about to ADD user " + user + " to the list of users \n to email. Continue?")) {
    				alert("User " + user + " will now be ADDED!");
    				addr.value +=strn
    				return true;
    			}
    			// ## This extra alert message can be removed if you wish., just remove the else statement ##
    			else {
    				alert("User " + user + " will not be ADDED!");
    				return false;
    			}
    			// ## Stop Else Statement for Alert Message ##
    		}
    	}
    }
    
    function formatEmail() {
    	var doct = window.document.title.toString(); // Set Var for Document Title.
    	var form = window.document.forms[0]; // Set Var for Forms.
    	var requ = form.reqRequestor_Email.value; // Set Var for Requestor Email.
    	var addr = form.reqAddresses.value; // Set var for Addresses.
    	var gstr = / /g; // Global Search for a space
    	var rep1 = addr.replace(gstr,"&cc="); // Replace all spaces with a &cc=
    	var rep2 = "mailto:" + rep1.replace("&","?") + requ + "&subject=" + doct; // Add mailto, replace the first & with a ?, add the requestor email, and add the subject.
    	
    	form.sentaddrs.value = rep2; // Set the value of the hidden form element to the value of the string.
    	alert("This is your Mailto String:\n" + form.sentaddrs.value); // ## This is for testing to see what your mailto string looks like ##
    }
    
    // Show Me -->
    </script>
    <!-- Stop Javascript -->
    
    </head>
    <body onLoad="focusIt();" text="#000000" bgcolor="#ffffff">
    <!-- Start Document -->
    
    <div align="center">
    <form method="post" enctype="text/plain" name="ADFVDS62" title="Advanced Form Validation Script v6.2" onSubmit="return checkForm(this)" onReset="return confirmReset()">
    <table width="500" border="0" cellspacing="3" cellpadding="1">
    <tr>
        <td colspan="2"><h2>Advanced Form Validation Script v6.2</h2></td>
    </tr>
    <tr>
        <td align="right" width="200" bgcolor="#e6e6e6"><b>* Requestor First Name:</b></td>
        <td width="300"><input type="text" name="reqRequestor_First_Name" size="20" maxlength="30" title="Requestor First Name"></td>
    </tr>
    <tr>
        <td align="right" width="200" bgcolor="#e6e6e6"><b>* Requestor Last Name:</b></td>
        <td width="300"><input type="text" name="reqRequestor_Last_Name" size="20" maxlength="30" title="Requestor Last Name"></td>
    </tr>
    <tr>
        <td align="right" width="200" bgcolor="#e6e6e6"><b>* Requestor Email:</b></td>
        <td width="300"><input type="text" name="reqRequestor_Email" size="20" maxlength="30" onBlur="validEmail();" title="Requestor Email"></td>
    </tr>
    <tr>
        <td align="right" width="200" bgcolor="#e6e6e6"><b>* Requestor Age:</b></td>
        <td width="300">
    	<input type="hidden" name="==================================================">
        <select name="reqRequestor_Age" title="Requestor Age">
        	<option selected>Choose your Age</option>
        	<option value="13 to 20">13 to 20</option>
        	<option value="21 to 31">21 to 31</option>
        	<option value="32 to 42">32 to 42</option>
        	<option value="43 to 53">43 to 53</option>
        	<option value="54 and Up">54 and Up</option>
        </select></td>
    </tr>
    <tr>
        <td align="right" valign="top" width="200" bgcolor="#e6e6e6"><b>* Requestor Sex:</b></td>
        <td width="300">
    		<input type="radio" name="reqRequestor_Sex" value="Male" title="Requestor Sex - Male Selection"> Male<br>
    		<input type="radio" name="reqRequestor_Sex" value="Female" title="Requestor Sex - Female Selection"> Female
    	</td>
    </tr>
    <tr>
        <td valign="top" align="right" width="200" bgcolor="#e6e6e6"><b>* Region:</b></td>
        <td width="300">
    		<input type="checkbox" name="reqRegion" value="North America" title="Region - North America"> North America<br>
    		<input type="checkbox" name="reqRegion" value="South America" title="Region - South America"> South America<br>
    		<input type="checkbox" name="reqRegion" value="Europe" title="Region - Europe"> Europe<br>
    		<input type="checkbox" name="reqRegion" value="Asia" title="Region - Asia"> Asia
    		<input type="hidden" name="==================================================">
    	</td>
    </tr>
    <tr>
        <td valign="top" align="right" width="200" bgcolor="#e6e6e6"><b>Click button for help</b></td>
        <td width="300"><input type="button" name="Help_Button" value="Help" onClick="alert('Fields with an * are required fields. \n\nTo see the generated report, click \non the Show Info button.')" title="Get Help on using this Form"></td>
    </tr>
    <tr>
        <td valign="top" align="right" width="200" bgcolor="#e6e6e6"><b>* Comments:</b></td>
        <td width="300" valign="top"><textarea cols=23 rows=5 name="reqSome_Comments" wrap="soft" title="Comments"></textarea></td>
    </tr>
    <tr>
        <td valign="top" align="right" width="200" bgcolor="#e6e6e6"><b>Select User or Users:</b></td>
        <td width="300" valign="top">
            <select name="reqCoEmail" onChange="addEmail(); formatEmail()" title="User Selection">
                <option selected>Choose a User</option>
                <option value="jon@phxnow.com">Jon at phxnow.com</option>
                <option value="r2045c@email.sps.mot.com">Jon at MOT</option>
                <option value="yarrokon@home.com">Yarrokon at home.com</option>
                <option value="info@phxnow.com">Information at phxnow.com</option>
            </select>
        </td>
    </tr>
    <tr>
        <td valign="top" align="right" width="200" bgcolor="#e6e6e6"><b>* Addresses to send to:</b></td>
        <td width="300" valign="top"><textarea cols=23 rows=5 name="reqAddresses" wrap="virtual" title="Addresses to send to"></textarea></td>
    </tr>
    <tr>
        <td align="right" width="200" bgcolor="#e6e6e6"><b>Action:</b></td>
        <td width="300">
    		<input type="hidden" name="==================================================">
    		<input type="submit" name="submit" value="Submit" title="Submit the form">
    		<input type="reset" name="reset" value="Reset" title="Reset the form">
    		<input type="button" name="show" value="Show Info" onClick="subThanks();" title="Show the Generated Sub Page">
    		<input type="hidden" name="sentaddrs">
    	</td>
    </tr>
    </table>
    </form>
    </div>
    
    <!-- Stop Document -->
    </body>
    </html>

  • #4
    Regular Coder
    Join Date
    Dec 2002
    Location
    Phoenix, Arizona, USA
    Posts
    148
    Thanks
    0
    Thanked 0 Times in 0 Posts
    On-line commented text. May not work for all browsers, which is why I posted it above.

    http://phxnow.com/resources/Scripts/Validation%20Form/

  • #5
    WA
    WA is offline
    Administrator
    Join Date
    Mar 2002
    Posts
    2,596
    Thanks
    2
    Thanked 19 Times in 18 Posts
    Hi Jon:
    Thanks for the submission. As noted here: READ THIS BEFORE YOU POST A SCRIPT , in the future, if the script is as long as this one, please attach it as a zip file, instead of showing it inline.
    - George
    - JavaScript Kit- JavaScript tutorials and 400+ scripts!
    - JavaScript Reference- JavaScript reference you can relate to.

  • #6
    Regular Coder
    Join Date
    Dec 2002
    Location
    Phoenix, Arizona, USA
    Posts
    148
    Thanks
    0
    Thanked 0 Times in 0 Posts
    Sorry, was going to make it one page, but saw you had a character max... so I split it... TY for the heads up.

  • #7
    Senior Coder
    Join Date
    Jun 2002
    Location
    41° 8' 52" N -95° 53' 31" W
    Posts
    3,660
    Thanks
    0
    Thanked 0 Times in 0 Posts
    I don't see any regular expression validation...
    Former ASP Forum Moderator - I'm back!

    If you can teach yourself how to learn, you can learn anything. ;)

  • #8
    Regular Coder
    Join Date
    Dec 2002
    Location
    Phoenix, Arizona, USA
    Posts
    148
    Thanks
    0
    Thanked 0 Times in 0 Posts
    Nope, customer did not want that.


    They wanted a form to check for content, make sure the fied would not pass validation for only spaces. Be able to change which fields are required based off adding a REQ in the field name, and open a new window to show what was sent, make it printable, and send the visitor a copy.

    I think thats pretty good... It was my first full use of JS in a form, besides the standard error checking.

    The customer was using a platform that had no way to send forms, accept though EMAIL. (UGH) so this was the way to do it.

    It does not cover everything some one would need in form validation, but its got some really nice tricks.

    Notice how you can add and remove users you want to send to! All though a drop list, the example also shows you how its building the email string.

    If for nothing else, this is a nice toy to play with for the beginner JS user.

  • #9
    Senior Coder
    Join Date
    Jun 2002
    Location
    41° 8' 52" N -95° 53' 31" W
    Posts
    3,660
    Thanks
    0
    Thanked 0 Times in 0 Posts
    No doubt... a bit long, but it has some good validation techniques. Personally I would rather write a real quick application-specific validation script myself.

    Good luck getting the users to write the correct HTML.
    Last edited by whammy; 12-12-2002 at 01:25 AM.
    Former ASP Forum Moderator - I'm back!

    If you can teach yourself how to learn, you can learn anything. ;)

  • #10
    Regular Coder
    Join Date
    Dec 2002
    Location
    Phoenix, Arizona, USA
    Posts
    148
    Thanks
    0
    Thanked 0 Times in 0 Posts
    LMAO!!!

    I never said it would be easy or that anyone would understand me, or that I even did it right ...



    TY Thought ???

  • #11
    Senior Coder
    Join Date
    Jun 2002
    Location
    41° 8' 52" N -95° 53' 31" W
    Posts
    3,660
    Thanks
    0
    Thanked 0 Times in 0 Posts
    Hey, I don't claim to know everything there is to know, either, and there are probably things I can learn from your validation... but I'm confused as to your statement "the customer did not want that" - if you're going to validate something the best way, the customer doesn't need to know how it's done, they only need to see the results.
    Former ASP Forum Moderator - I'm back!

    If you can teach yourself how to learn, you can learn anything. ;)

  • #12
    Regular Coder
    Join Date
    Dec 2002
    Location
    Phoenix, Arizona, USA
    Posts
    148
    Thanks
    0
    Thanked 0 Times in 0 Posts
    True, very true... Hindsight is 20/20!

    BTW, when you going to finish your site update?

  • #13
    Senior Coder
    Join Date
    Jun 2002
    Location
    41° 8' 52" N -95° 53' 31" W
    Posts
    3,660
    Thanks
    0
    Thanked 0 Times in 0 Posts
    Ugh... touche!

    Actually I am working on it a bit right now, I have a whole new design and plans for including a LOT more helpful content, some of which is ready to go...

    ...but I have to figure out how to work in the old database (and the old pages) without causing anyone using my form mail services to have any problems, as surprisingly there are a lot of people from China to Australia using it! And that is one of the things about the internet that is just amazing to me.

    Should be pretty simple but I haven't had much time lately.
    Former ASP Forum Moderator - I'm back!

    If you can teach yourself how to learn, you can learn anything. ;)

  • #14
    New to the CF scene
    Join Date
    May 2004
    Posts
    2
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Dear JonT how does your Javascript distinguishes between...

    HOw javascript distinguishes between the names of the textfields, radio, and select-one in the function checkform(). I understand that it uses showName to get for eg. reqRequestor_First_Name. However how it does it i cannot understand!

    SOME HELP PLEASE???

  • #15
    Regular Coder
    Join Date
    Dec 2002
    Location
    Phoenix, Arizona, USA
    Posts
    148
    Thanks
    0
    Thanked 0 Times in 0 Posts
    fgau1, forms are an array of items, that hold what it is, and information about it. Imagine your house, and all the items in it. Your house is the form, and every item in it is a piece of the form. The array knows you have a TV, that it is Color, and that it can play DVD's, it's make and model and all of its properties.

    When I loop though the form, it returns the forms name, type and other information about the form fiields, which is why you see validation for text fields, drop lists and then radio / check boxes.

    This form will not display a message for a specific form field name, the alert will be provided for all missing fields. This was mainly written for very large forms, I used this for forms that had over 50 Fields in them, and the customer could not make up their mind on what should and should not be validated. There are 100 ways one can validate a form, this is just simply one of them and as whammy was saying it does have some good ideas, but is not the best for everything. So this script, although could be used, is best in most cases as a learning process to help give you ideas, and how to validate specific field types.

    If your using Dreamweaver, you may just want to use the built-in feature of dreamweavers validation.


  •  
    Page 1 of 2 12 LastLast

    Posting Permissions

    • You may not post new threads
    • You may not post replies
    • You may not post attachments
    • You may not edit your posts
    •