I’ve got a basic HTML/JavaScript contact form that HostGator provided. It works pretty well…if user submits no name or invalid email address, a JavaScript alert pops-up that says so. These alerts stay on the screen until user clicks OK. However, if user submits contact form correctly, the final success alert only lasts for 1/2 a second or so. I’m trying to figure out how to make the final email success alert last for a specified time, either that or until user clicks on the OK button at which point they are redirected to specified page. Here is the link to the HostGator info on contact form w/ JavaScript http://www.hostgator.com/formmail.shtml and here is the code which I’m trying to change to get post-submit JavaScript message to stick around instead of disappearing before the user even has a chance to read it.
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
<meta http-equiv="content-type" content="text/html;charset=utf-8">
<title>FormMail Demo</title>
<script type="text/javascript">
function hgsubmit()
{
if (/\S+/.test(document.hgmailer.name.value) == false) alert ("Please provide your name.");
else if (/^\S+@[a-z0-9_.-]+\.[a-z]{2,6}$/i.test(document.hgmailer.email.value) == false) alert ("A valid email address is required.");
else if (/\S+/.test(document.hgmailer.comment.value) == false) alert ("Your email content is needed.");
else {
document.hgmailer.submit();
alert ('Thank you!\nYour email is sent.');
}
}
</script>
</head>
<body>
<form action="http://www.mydomain.com/cgi-sys/formmail.pl" method="post" name="hgmailer">
<input type="hidden" name="recipient" value="myemail@mydomain.com">
<input type="hidden" name="subject" value="FormMail E-Mail">
Whatever you want to say here<br><br>
Visitor Name: <input type="text" name="name" size="30" value=""><br>
Visitor E-Mail: <input type="text" name="email" size="30" value=""><br>
E-Mail Content: <textarea name="comment" cols="50" rows="5"></textarea><br><br>
<input type="button" value="E-Mail Me!" onclick="hgsubmit();">
<input type="hidden" name="redirect" value="http://www.mydomain.com/redirect-path">
</form>
</body>
</html>
This should do the alert(), wait 4 seconds (or whatever you specify in the second paramter) and then do the submit().