Posts: 159
Location: Skegness, Lincolnshire, England
|
A function similar to that below will do it:
Code:
<script language="JavaScript">
function sub_check() {
d = document.newsletter;
if (d.email.value == "") { alert("Please enter an email address"); return(false) }
URL = "subscribe.php?email="+e;
window.location = URL;
}
</script>
You will, of course, need to change the form and field names to suit those you have used, and don't forget to use an opening <form> tag in the form of
Code:
<form action='' name='newsletter' id='newsletter' onSubmit='sub_check(); return(false)'>
Notice that the action is left blank in the form as the JavaScript actually takes care of that for you.
As Submit buttons can sometimes be a pain in the a** I always tend to use an image in the form:
Code:
<img src='images/subscribe.jpg' width='84' height='34' border='0' onClick='sub_check()'>
In case you are wondering why the routine is included in the <form> twice, this is done to ensure that people pressing the return key rather than clicking on the submit button are also sent via the error cheching routine.
I hope that clears things up for you.
|