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>