Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations bkrike on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Form validation, email and open a link problem

Status
Not open for further replies.

rkasnick

Programmer
Apr 28, 2003
66
US
This one has me vexed. I am trying to validate two fields, name and email address, if the validation passes then send an email with both, and then open a form which has a download link on it. I want to have these three actions all performed with the same 'submit' button (one click of the mouse). Here's the code that I have but it's not working. Can anyone provide some tips or a healthy push in the right direction?? Much thanks.

<SCRIPT LANGUAGE="javascript">
<!--
function verify() {
obj = document.forms[0]; // Assuming this is the first form on the page
if (obj.FName.value == "") {
err = obj.FName;
} else if (obj.Email.value == "") {
err = obj.Email;
} else {
obj.submit();
}
alert("Please fill in all fields.");
eval(err).focus();
}
//-->
</SCRIPT>
.
.
.
<FORM ACTION="mailto:info@wizdomworks.us" METHOD="POST" onSubmit="return confirm('Thank you.')">
<PRE>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; Name:&nbsp;<INPUT TYPE="TEXT" NAME="Fname" SIZE="40"></PRE>

<PRE>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; E-mail:&nbsp;<INPUT TYPE="text" NAME="Email" SIZE="40"></PRE>
<tr>
<input type="button" value="Submit" onClick="verify()"
href=" height=40 width=100 >
</tr>
 
How's something like this?

Code:
<html>
<head>
<script>
function verify()
{
 var verified = true;

 var obj = document.forms[0];  // Assuming this is the first form on the page
 var err;
 if (obj.FName.value == "") 
 {
     err = obj.FName;
     verified = false;
 }//end if
 else if (obj.Email.value == "") 
 {
     err = obj.Email;
     verified = false;
 }//end else if

 var subject = "Check this out!";
 var body = "Hey " + obj.FName.value + "!  Check out this site!  [URL unfurl="true"]http://www.wizdomworks.us/downloadit.html.[/URL] --me";

 if(verified)
 {
  //launch mail (won't SEND it though)
  mailAnchor.href = 'mailto:'+obj.Email.value+'?subject='+escape(subject)+'&body='+escape(body);
  mailAnchor.click();

  //redirect to new location
  this.location = "[URL unfurl="true"]http://www.wizdomworks.us/downloadit.html";[/URL]
 }//end if
 else
 {
  alert("Please fill in all fields.");
  eval(err).focus();
 }//end else
}//end verify()
</script>
</head>
<body>
<form>
<input name='FName' type='text' size='30'><br />
<input name='Email' type='text' size='30'><br />
<input type='button' value='submit' onclick='verify()' />
<a id='mailAnchor' href=''></a>
</form>
</body>
</html>

Here, I am assuming the user is sending an e-mail to someone else.

If you want the "web page" to send an e-mail to the user, then you need to do some server side stuff.

--Dave
 
Thanks Dave, with a few minor modifications to your code your help did it. Too bad about the page not sending the email, since I don't have access to the server side, I guess asking the surfer to click "send" is the best way, even though they could cancel out and still get the download page, it's better than what I had. Many thanks.

Rod
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top