Results 1 to 7 of 7

Thread: Required field(s) validation

  1. #1
    Join Date
    Nov 2005
    Posts
    4
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Default Required field(s) validation

    Script Required field(s) validation
    http://www.dynamicdrive.com/dynamici...uiredcheck.htm
    This does not appear to work with a mailto: command. Please tell me what I am doing wrong.
    Here is my form code at the top in the body tag I have the script.
    Thanks for any help. Please e-mail me or post back to this forum.


    <form action="mailto:help@gothiclandscape.com" method="post" enctype="text/plain" name="ITOrder" onsubmit="return ITOrder(this);">
    <table width="427" border="1">
    <tr>
    <td width="161">What user is this for?</td>
    <td width="84"><strong>First Name</strong></td>
    <td width="160"><input name="firstname" type="text" id="firstname"></td>
    </tr>
    <tr>
    <td>&nbsp;</td>
    <td><strong>Last Name </strong></td>
    <td><input name="lastname" type="text" id="lastname"></td>
    </tr>
    </table>
    <input name="submit" type="submit" value="submit">
    </form>

  2. #2
    Join Date
    Jun 2005
    Location
    英国
    Posts
    11,876
    Thanks
    1
    Thanked 180 Times in 172 Posts
    Blog Entries
    2

    Default

    By the fact that your function name isn't the same as in the original script. From this I deduce that you've probably changed it in some way. If this is the case, PLEASE: Include the URL to your problematic webpage that you want help with. If not, you need to use exactly the code supplied:
    Code:
    onsubmit="return formCheck(this);"
    Twey | I understand English | 日本語が分かります | mi jimpe fi le jbobau | mi esperanton komprenas | je comprends français | entiendo español | tôi ít hiểu tiếng Việt | ich verstehe ein bisschen Deutsch | beware XHTML | common coding mistakes | tutorials | various stuff | argh PHP!

  3. #3
    Join Date
    Nov 2005
    Posts
    4
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Default

    I changed the function name to formcheck and it still bypasses the checking and begins to process sending the e-mail. This is a intranet site so I cannot send you the link.

  4. #4
    Join Date
    Jun 2005
    Location
    英国
    Posts
    11,876
    Thanks
    1
    Thanked 180 Times in 172 Posts
    Blog Entries
    2

    Default

    In that case, please post your page code here, inside [code] tags.
    Twey | I understand English | 日本語が分かります | mi jimpe fi le jbobau | mi esperanton komprenas | je comprends français | entiendo español | tôi ít hiểu tiếng Việt | ich verstehe ein bisschen Deutsch | beware XHTML | common coding mistakes | tutorials | various stuff | argh PHP!

  5. #5
    Join Date
    Nov 2005
    Posts
    4
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Default

    Code:
    <!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN"
    "http://www.w3.org/TR/html4/loose.dtd">
    <html>
    <head>
    <script language="JavaScript">
    <!--
    
    /***********************************************
    * Required field(s) validation v1.10- By NavSurf
    * Visit Nav Surf at http://navsurf.com
    * Visit http://www.dynamicdrive.com/ for full source code
    ***********************************************/
    
    function formCheck(formobj){
    	// Enter name of mandatory fields
    	var fieldRequired = Array("FirstName", "LastName");
    	// Enter field description to appear in the dialog box
    	var fieldDescription = Array("First Name", "Last Name");
    	// dialog message
    	var alertMsg = "Please complete the following fields:\n";
    	
    	var l_Msg = alertMsg.length;
    	
    	for (var i = 0; i < fieldRequired.length; i++){
    		var obj = formobj.elements[fieldRequired[i]];
    		if (obj){
    			switch(obj.type){
    			case "select-one":
    				if (obj.selectedIndex == -1 || obj.options[obj.selectedIndex].text == ""){
    					alertMsg += " - " + fieldDescription[i] + "\n";
    				}
    				break;
    			case "select-multiple":
    				if (obj.selectedIndex == -1){
    					alertMsg += " - " + fieldDescription[i] + "\n";
    				}
    				break;
    			case "text":
    			case "textarea":
    				if (obj.value == "" || obj.value == null){
    					alertMsg += " - " + fieldDescription[i] + "\n";
    				}
    				break;
    			default:
    			}
    			if (obj.type == undefined){
    				var blnchecked = false;
    				for (var j = 0; j < obj.length; j++){
    					if (obj[j].checked){
    						blnchecked = true;
    					}
    				}
    				if (!blnchecked){
    					alertMsg += " - " + fieldDescription[i] + "\n";
    				}
    			}
    		}
    	}
    
    	if (alertMsg.length == l_Msg){
    		return true;
    	}else{
    		alert(alertMsg);
    		return false;
    	}
    }
    // -->
    </script>
    
    <meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1">
    <title>Untitled Document</title>
    </head>
    
    <body>
    <form action="mailto:help@gothiclandscape.com" method="post" enctype="text/plain" name="ITOrder" onsubmit="return formcheck(this);">
    <table width="427" border="1">
    <tr>
    <td width="161">What user is this for?</td>
    <td width="84"><strong>First Name</strong></td>
    <td width="160"><input name="firstname" type="text" id="firstname"></td>
    </tr>
    <tr>
    <td>&nbsp;</td>
    <td><strong>Last Name </strong></td>
    <td><input name="lastname" type="text" id="lastname"></td>
    </tr>
    </table>
    <input name="submit" type="submit" value="submit">
    </form>
    
    </body>
    </html>

  6. #6
    Join Date
    Jun 2005
    Location
    英国
    Posts
    11,876
    Thanks
    1
    Thanked 180 Times in 172 Posts
    Blog Entries
    2

    Default

    Very simple error: it's formCheck(this), not formcheck(this). Case is important.
    Code:
    <form action="mailto:help@gothiclandscape.com" method="post" enctype="text/plain" name="ITOrder" onsubmit="return formCheck(this);">
    Twey | I understand English | 日本語が分かります | mi jimpe fi le jbobau | mi esperanton komprenas | je comprends français | entiendo español | tôi ít hiểu tiếng Việt | ich verstehe ein bisschen Deutsch | beware XHTML | common coding mistakes | tutorials | various stuff | argh PHP!

  7. #7
    Join Date
    Nov 2005
    Posts
    4
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Default

    I changed the case to
    Code:
    <form action="mailto:help@gothiclandscape.com" method="post" enctype="text/plain" name="ITOrder" onsubmit="return formCheck(this);">
    but when I open this in Internet Explorer with no value in the First Name and Last Name fields it does not prompt saying please complete the following fields.
    What am I doing wrong?
    Thanks for all your help.

Bookmarks

Posting Permissions

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