...

View Full Version : Form to Email



pope
08-01-2002, 06:51 AM
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 ^_^

ShriekForth
08-01-2002, 05:20 PM
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.


<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



EZ Archive Ads Plugin for vBulletin Copyright 2006 Computer Help Forum