/    Sign up×
Community /Pin to ProfileBookmark

help w/form validation & thankyou page

I have a basic form with validation. Each field is required to be filled in. If all the fields are completed, after submission, I want the person to be directed to “thanks.htm”. How can I make this work? Here’s the code:

<body onLoad=”checkData()”>

<!– START OF SCRIPT –>

<script language=”JavaScript”>

<!–
function checkData (){
if (document.prayerrequest.NAME.value == “”) {
alert(“Please fill in your Name.”)
document.prayerrequest.NAME.focus()
return false}
if (document.prayerrequest.TELEPHONE.value == “”) {
alert(“Please fill in your Telephone Number.”)
document.prayerrequest.TELEPHONE.focus()
return false}
if (document.prayerrequest.DATE.value == “”) {
alert(“Please fill in Date of Request.”)
document.prayerrequest.DATE.focus()
return false}
if (document.prayerrequest.PRAYERREQUEST.value == “”) {
alert(“Please fill in your Prayer request.”)
document.prayerrequest.PRAYERREQUEST.focus()
return false}

}

// –>

function doVerify()
{
location.href = “thanks.htm”
}

</script>

<form action=”mailto:[email protected]?cc=[email protected]” method=”POST” enctype=”text/plain” name=”prayerrequest” onsubmit=”return checkData()”; “doVerify()”>

<pre>
1. Name <textarea name=”NAME” rows=”1″ cols=”70″></textarea>
<br>
2. Telephone Number <textarea name=”TELEPHONE” rows=”1″ cols=”20″></textarea>
<br>
3. Date of request <textarea name=”DATE” rows=”1″ cols=”20″></textarea>
<br>
4. Care request and/or prayer needed.
<br>
<center><textarea name=”PRAYERREQUEST” rows=”20″ cols=”75″ wrap></textarea></center>

<br>
<center><INPUT TYPE=”submit” VALUE=”SEND EMAIL!”> <INPUT TYPE=”reset” VALUE=”CLEAR FORM”></center>

</pre>

</form>
<!– END OF SCRIPT –>
</font></font></strong>
</body>

Thanks for any help in making this work.

to post a comment
JavaScript

7 Comments(s)

Copy linkTweet thisAlerts:
@JonaJun 17.2004 — [font=arial]You should be using Regular Expressions for your validation, making it more secure.

Regarding your actual question, though, since there is no way to tell if someone has sent the email or not because you are using the mailto protocol, the most you can do is assume that they will send you an email if the form verifies. To do this, your form's [b]onsubmit[/b] attribute should look like this.[/font]

<i>
</i>onsubmit="return checkData(); doVerify();"


[font=arial]Hope this helps.[/font]
Copy linkTweet thisAlerts:
@mrsjoecoolauthorJun 17.2004 — I already have the code that you suggested: onSubmit="return checkData(); doVerify()" in the FORM tag. It still doesn't work. It will check that the fields are filled in, but once all the fields are completed and the "submit button" is pressed, it should go to the "thanks.htm" page, but it doesn't. Is there something else to try? I'm a newbie and I'm stumped. Thanks.
Copy linkTweet thisAlerts:
@JonaJun 17.2004 — [i]Originally posted by mrsjoecool [/i]

[B]I already have the code that you suggested: onSubmit="return checkData(); doVerify()" in the FORM tag.[/B][/QUOTE]


[font=arial]Actually, you do not. You have:[/font]

<i>
</i>onsubmit="return checkData()"; "doVerify()"


[font=arial]It should be:[/font]

<i>
</i>onsubmit="return checkData(); doVerify();"
Copy linkTweet thisAlerts:
@mrsjoecoolauthorJun 17.2004 — I appreciate the correction in coding. I changed the code to:

onsubmit="return checkData(); doVerify();"

However, if the form is submitted with some blank fields, it is still being directed to the "thanks.htm" page. I want it to only go the "thanks.htm" page when and if all the fields are completed. Thanks.
Copy linkTweet thisAlerts:
@JonaJun 17.2004 — [font=arial]Add the following code just before the closing brace (}) in your checkData function.[/font]

<i>
</i>doVerify();
Copy linkTweet thisAlerts:
@mrsjoecoolauthorJun 18.2004 — Thanks Jona for all your help. That worked!
Copy linkTweet thisAlerts:
@JonaJun 18.2004 — [font=arial]Happy to help![/font]
×

Success!

Help @mrsjoecool spread the word by sharing this article on Twitter...

Tweet This
Sign in
Forgot password?
Sign in with TwitchSign in with GithubCreate Account
about: ({
version: 0.1.9 BETA 5.3,
whats_new: community page,
up_next: more Davinci•003 tasks,
coming_soon: events calendar,
social: @webDeveloperHQ
});

legal: ({
terms: of use,
privacy: policy
});
changelog: (
version: 0.1.9,
notes: added community page

version: 0.1.8,
notes: added Davinci•003

version: 0.1.7,
notes: upvote answers to bounties

version: 0.1.6,
notes: article editor refresh
)...
recent_tips: (
tipper: @Yussuf4331,
tipped: article
amount: 1000 SATS,

tipper: @darkwebsites540,
tipped: article
amount: 10 SATS,

tipper: @Samric24,
tipped: article
amount: 1000 SATS,
)...