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.
Results 1 to 2 of 2

Thread: Form to Email

  1. #1
    New to the CF scene
    Join Date
    Jul 2002
    Posts
    4
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Smile Form to Email

    I want to create a form like this:

    http://www.hkcca.com/html/traact.htm

    Anyone can help me where can I find such coding? I found that it use asp to do the checking. If i want to use javascript to do this function, can I and where can I find more information about this? Thanks ^_^

  • #2
    Regular Coder
    Join Date
    Jul 2002
    Location
    Western US
    Posts
    169
    Thanks
    0
    Thanked 0 Times in 0 Posts
    If you just want to use javascript to check to see if the fields are filled in this is pretty easy. If you want to display a message to the user it's just a combination of a few functions. I wrote this a few weeks ago for someone else. It shows the errors in a new window, not in the one the form was in. But it might serve your purpose, or give you an idea on where to start. It only does required validation, it could be modified to check formats, and lenghts with a couple more funtions.

    Code:
    <html>
    <head>
    <body >
    <form name=temp method="post" action="popUpError.html" onSubmit="return validateForm(this)">
    <b>First</b>: <input type="text" name="Question1" value=""><br>
    <b>Second</b>: <input type="text" name="Question2" value=""><br>
    <b>Third</b>: <input type="text" name="Question3" value=""><br>
    <input type="submit" name="submit" value="Send it">
    </form>
    
    <script language="JavaScript" type="text/javascript">
    function validateForm(theForm){
    	errMsg = ""
    	errMsg = errMsg + isRequired(theForm.Question3, "Third Question");
    	errMsg = errMsg + isRequired(theForm.Question2, "Second Question");
    	errMsg = errMsg + isRequired(theForm.Question1, "First Question");
    	if (errMsg.length > 0){
    		showErrorWindow(errMsg);
    		return false;
    	}
    	else{
    		return true;
    	}
    }
    
    function isRequired(item, displayName){
    	if (item.value == ""){
    		item.focus();
    		return "\n <b>" + displayName + "</b> is a required field<br>";
    	}
    	else
    		return "";
    }
    
    function showErrorWindow(errorMessage){
    	errwin=window.open("","ErrorWindow","  toolbar=no,status=yes,maximize=no,menubar=no,scrollbars=yes,width=500,height=500");
    	errwin.document.clear();
    	errwin.document.writeln('<html><body>\n');
    	errwin.document.writeln(errorMessage);
    	errwin.document.writeln('\n<a href="javascript:window.close();">Close</a> this window, and fill in the appropriate fields.\n</body></html>');
    	errwin.document.close();
    }
    </script>
    
    </body>
    </html>
    ShriekForth


  •  

    Posting Permissions

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