473,545 Members | 1,989 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

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="te xt/html" %>
<%@ taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core" %>
<HTML>

<script>
function validateform(fo rm)
{
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>Quo tation Request Form</H2></CENTER>

<FORM NAME="QuoteForm " METHOD=POST ACTION="QuoteRe q2.jsp" onSubmit="retur n
validateform(th is)">

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

<c:if test="${param.s ubmitted && 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.s ubmitted && 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.s ubmitted && 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 2357
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(fo rm)
{
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.javas cript 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="te xt/html" %>
<%@ taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core" %>
<HTML>

<script>
function validateform(fo rm)
{
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>Quo tation Request Form</H2></CENTER>

<FORM NAME="QuoteForm " METHOD=POST ACTION="QuoteRe q2.jsp" onSubmit="retur n validateform(th is)">

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

<c:if test="${param.s ubmitted && 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.s ubmitted && 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.s ubmitted && 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
1947
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 alert box should pop up notifying the client. Now if one is empty it should let the form to process thanks
6
2133
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. could you please have a look at the following script: ------------------------------------------------------------
1
4465
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 current window. I have a cgi script provided by my web host to send the contents of the form through email but they only show me how to use the cgi...
11
2108
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 TextBox. But now, when I input a string in the textbox and press Enter key, the form was submit without client javascript validate. Why? And what should...
3
5947
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 validators, so I have a button on the form and the "causes validation" property is set to true. I have overridden the "Validate()" like so
1
359
by: jayparaiso | last post by:
Hi! How to validate check box and drop down menu in one form?
11
8133
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 to validate 3 types of fields: text, radio button, dropdown menu. but the code doesn't validate. After 2 days, it's time I asked for guidence....
10
6832
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 validate some inputs of this form, so I submit it to a PHP page in my own server first.
1
3978
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. Depends on the pull down list selection, I use script.aculo.us to validate the user input before submit and pass the necessary data, such as contact...
2
1932
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 validate a form. Its quite a simple form, but I am a wee bit stuck. Baically it consists of 9 text input fields and a select element. All elements on...
0
7487
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main...
0
7420
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 effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language...
0
7680
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, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. ...
0
7934
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 tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that...
1
7446
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 Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For...
0
7778
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the...
0
6003
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, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then...
0
3459
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
0
731
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating...

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.