473,406 Members | 2,867 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,406 software developers and data experts.

Validate form for email

The following code asks the user to sumbit a name, email address, and some
text for a quotation via a FORM. I have written a javascript function to
evaluate the fields in the form and pop-up a message to tell the user if all
the fields have been fill-out. If the user has missed some information the
form re-displays with red "alerts" indicating where the user have missed the
information while re-populating the information the user has submitted.

May question is, after the user has successfully filled out the form, how
can the submit request be forwarded to another jsp so the information can be
emailed to me. I have written a jsp to accept the request and email it. This
works if I remove the validation code. I am not familiar enough with
javascript to be able to figure this one out. I may be on the wrong track.

Please help...

Here is my code .... (file is called QuoteReq2.jsp)

<%@ page contentType="text/html" %>
<%@ taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core" %>
<HTML>

<script>
function validateform(form)
{
questions = form.elements;

if ((questions['toname'].value=="")||
(questions['emailto'].value=="")||
(questions['quote'].value==""))
{ alert("Some information is missing from your request.")
}

}
</script>

<HEADER>
<TITLE>
Quotation Request
</TITLE>
</HEADER>
<BODY>
<CENTER><H2>Quotation Request Form</H2></CENTER>

<FORM NAME="QuoteForm" METHOD=POST ACTION="QuoteReq2.jsp" onSubmit="return
validateform(this)">

<input type="hidden" name="submitted" value="true">

<c:if test="${param.submitted && empty param.toname}">
<font color="red">
Please enter your Name<br>
</font>
</c:if>
Your Name :
<INPUT TYPE=TEXT NAME="toname" Size=4O value="<c:out value="${param.toname}"
/>">
<br>
<br>

<c:if test="${param.submitted && empty param.emailto}">
<font color="red">
You have not entered an E-Mail address.<br>
</font>
</c:if>
E-Mail :
<INPUT TYPE=TEXT NAME="emailto" Size=45 value="<c:out
value="${param.emailto}" />"><br>

<c:if test="${param.submitted && empty param.quote}">
<font color="red">
You have not entered any information for the quotation.<br>
</font>
</c:if>
<br>
<br>
Enter your quotation request :<br>
<TEXTAREA NAME="quote" rows=15 cols=60 wrap=soft>
<c:out value="${param.quote}" />
</TEXTAREA>
<br>
<br>
<INPUT TYPE="image" NAME="submit" src="/buttons/Submit.jpg" border=0
alt="Submit">
</FORM>
</BODY>
</HTML>
Jul 23 '05 #1
2 2340
Tim Mills wrote:
May question is, after the user has successfully filled out the form, how
can the submit request be forwarded to another jsp so the information can be
emailed to me. I have written a jsp to accept the request and email it. This
works if I remove the validation code. I am not familiar enough with
javascript to be able to figure this one out. I may be on the wrong track.

Please help...

<--snip-->
function validateform(form)
{
questions = form.elements;

if ((questions['toname'].value=="")||
(questions['emailto'].value=="")||
(questions['quote'].value==""))
{ alert("Some information is missing from your request.")

return false;

}


else{return true}
Inside the if that stops navigation, return false. Otherwise, return true.

<--snip-->
--
Randy
comp.lang.javascript FAQ - http://jibbering.com/faq
Jul 23 '05 #2
Tim Mills wrote:
The following code asks the user to sumbit a name, email address, and some text for a quotation via a FORM. I have written a javascript function to evaluate the fields in the form and pop-up a message to tell the user if all the fields have been fill-out. If the user has missed some information the form re-displays with red "alerts" indicating where the user have missed the information while re-populating the information the user has submitted.
May question is, after the user has successfully filled out the form, how can the submit request be forwarded to another jsp so the information can be emailed to me. I have written a jsp to accept the request and email it. This works if I remove the validation code. I am not familiar enough with
javascript to be able to figure this one out. I may be on the wrong track.
Please help...

Here is my code .... (file is called QuoteReq2.jsp)

<%@ page contentType="text/html" %>
<%@ taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core" %>
<HTML>

<script>
function validateform(form)
{
questions = form.elements;

if ((questions['toname'].value=="")||
(questions['emailto'].value=="")||
(questions['quote'].value==""))
{ alert("Some information is missing from your request.")
}

}
</script>

<HEADER>
<TITLE>
Quotation Request
</TITLE>
</HEADER>
<BODY>
<CENTER><H2>Quotation Request Form</H2></CENTER>

<FORM NAME="QuoteForm" METHOD=POST ACTION="QuoteReq2.jsp" onSubmit="return validateform(this)">

<input type="hidden" name="submitted" value="true">

<c:if test="${param.submitted && empty param.toname}">
<font color="red">
Please enter your Name<br>
</font>
</c:if>
Your Name :
<INPUT TYPE=TEXT NAME="toname" Size=4O value="<c:out value="${param.toname}" />">
<br>
<br>

<c:if test="${param.submitted && empty param.emailto}">
<font color="red">
You have not entered an E-Mail address.<br>
</font>
</c:if>
E-Mail :
<INPUT TYPE=TEXT NAME="emailto" Size=45 value="<c:out
value="${param.emailto}" />"><br>

<c:if test="${param.submitted && empty param.quote}">
<font color="red">
You have not entered any information for the quotation.<br>
</font>
</c:if>
<br>
<br>
Enter your quotation request :<br>
<TEXTAREA NAME="quote" rows=15 cols=60 wrap=soft>
<c:out value="${param.quote}" />
</TEXTAREA>
<br>
<br>
<INPUT TYPE="image" NAME="submit" src="/buttons/Submit.jpg" border=0
alt="Submit">
</FORM>
</BODY>
</HTML>


Question: why aren't you doing the entire validation - field checks,
prompting (including those 'red alerts') - and rejecting submission -
at the client? Typically a validator is written to trap as many errors
as possible: JavaScript isn't jsp, but it isn't a toy language either.
Once submission is permitted, always do bullet-proof validation at the
server, naturally.

If you're round-tripping anyway (with errors) there's not much point in
using browser validation...

Interesting tag: <HEADER>

Jul 23 '05 #3

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

1
by: Techy | last post by:
I have two fields in my form so called : invoice and cash Now I want to validate this form on the client side with the help of javascript in such a way that if one of these fields is empy an...
6
by: francisco lopez | last post by:
ok , first of all sorry if my english is not so good, I do my best. here is my problem: I don´t know much javascript so I wrote a very simple one to validate a form I have on my webpage. ...
1
by: mhawkins19 | last post by:
I have a form built and on the onclick event I validate all of the fields and then if the form is ok, on the submit event I run a javascript function to set a cookie and download a file from the...
11
by: wolf | last post by:
There are three webcontrol on my asp.net form: a TextBox, a submit button and a RegularExpressionValidator. And I had set ControlToValidate property of the RegularExpressionValidator to the...
3
by: Martin | last post by:
Hi, I am implemeting a form in asp.net. The form is quite large and the validation is reasonably complex, so I have decieded to implement my own validation rather than use any custon...
1
by: jayparaiso | last post by:
Hi! How to validate check box and drop down menu in one form?
11
by: TokyoJ | last post by:
I run a small camp in Alaska for kids and my director is asking for a web form. Could someone please have a look and offer some advice on where I'm making mistake(s)? I'm using the RegExp function...
10
by: kelvin | last post by:
Hi, A difficult question. I have a form that I used to submit to https://www. paypal.com/cgi-bin/ webscr <form action="https://www. paypal.com/cgi-bin/webscr" method="post"> Now I need to...
1
by: SkipNRun | last post by:
I am a novice when comes to JavaScript, AJAX. I am working on a form, which will allow users to update their contact information. In order to make the form flexible, I need to use pull down list. ...
2
by: Mick Walker | last post by:
Hi, I have a problem that I have been trying to figure for a couple of days, and am wondering if anyone out there would be so kind as to give me a solution. (Deadline time) I am trying to...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
0
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.