/    Sign up×
Community /Pin to ProfileBookmark

Trouble With JavaScript Form Validation

I have created a CGI script that prints the parameters of an integrated html form along with their values. In essence, it is a user application form that prints a confirmation message to the user after it is submitted. This has been accomplished, but my next task is form validation. I have tried dozens of examples, but I can’t get anything to work for my form.

As opposed to creating an html form and having it use a separate CGI script (IE form action=script.cgi), I simply printed a huge block of html code (the form) after the CGI script that prints the parameters. So, my script and form is contained on just one file, userapp.cgi.

Anyway, if anyone could just write me a few lines of code that would at least validate maybe one of my text fields (IE a pop-up that tells the user the First Name field is empty), I would be very grateful. If I can get the validation to work with one field, than I can do the rest of the dirty work applying it to all of them.

here is my script:

#!/usr/bin/perl

use CGI ‘:standard’;
print header;
print start_html(‘Code 974 New User Account Application Form’);
if (param()) {
print ‘<body bgcolor=FFDAB9><a href=”http://hsb.gsfc.nasa.gov”><img SRC=”gif/hydro.sm.gif” align=”left” valign=”top”></a><a href=”http://www.nasa.gov”><img SRC=”gif/NASAlogo.gif” valign=”top” align=”right”></a></align>
<center><h1>Thank You</h1>’;
print “<br><i><h2>Your information has been succesfully submitted</h2></i><br><hr><br><br></center>”;
my @params = param();
foreach my $parameter(@params) {
print “<b>”, $parameter,”</b>”, ” – “, param($parameter),”<br>”;
}
print ‘<br><center><font size=”+2″>To resubmit, please click <a href=”http://lshp.gsfc.nasa.gov/status/userapp.cgi”>here</a></font></center><br><br>’;
print ‘<hr color=”” size=5 width=90%>
</center><pre>
Please send any additional questions or comments to <a HREF=”MAILTO:[email protected]“>[email protected]</a>
Responsible NASA Official: <A HREF=”mailto:[email protected]“>Dr. Paul Houser</A>
This site maintained by: <A HREF=”mailto:[email protected]“>Sam Brin</A>
Goddard Space Flight Center
Greenbelt, MD 20711<BR></pre>’
} else {
print <<“END_OF_TEXT”;
<html>
<body bgcolor=FFFFFF>
<center>
<a href=”http://hsb.gsfc.nasa.gov”><img SRC=”gif/hydro.sm.gif” align=”left” valign=”top”></a><a href=”http://www.nasa.gov”><img SRC=”gif/NASAlogo.gif” valign=”top” align=”right”></a></align>
<br><h2>Code 974 New User Account Application Form</h2>
</h2></valign>
<FONT SIZE=+1>Last updated on: </B><I>10 July 2003</I></FONT><BR><BR>
<form name=”userapp”>
<br>
<br>
<hr color=”” size=5 width=80%>
<br>
<br>
<b><i><font size=+2>Personal Information</i></b></font>
<table BORDER=”3″ BORDERCOLOR=”000000″ WIDTH=”830″ BGCOLOR=”FFDAB9″>
<caption>&nbsp;</caption>
<tr>
<td>First Name*</td>
<td><input TYPE=”text” NAME=”FirstName” VALUE=”” SIZE=80 MAXLENGTH=80></td>
</tr>
<tr>
<td>Last Name*

<td><input TYPE=”text” NAME=”LastName” VALUE=”” SIZE=80 MAXLENGTH=80></td>
</tr>
<tr>
<td>GSFC IdentificationNumber</td>
<td><input TYPE=”text” NAME=”GSFCIDNumber” VALUE=”” SIZE=80 MAXLENGTH=80></td>
</tr>
<tr>
<td>Fax Number<td><input TYPE=”text” NAME=”FaxNumber” VALUE=”” SIZE=80 MAXLENGTH=80></td>
</tr>

<tr>
<td>Location (Building and Room Number)*</td>
<td><input TYPE=”text” NAME=”Location” VALUE=”” SIZE=80 MAXLENGTH=80></td>
<tr>
<td>E-mail*

<td><input TYPE=”text” NAME=”Email” VALUE=”” SIZE=80 MAXLENGTH=80></td>
</tr>
<tr>
<td>Title
<td><input TYPE=”text” NAME=”Title” VALUE=”” SIZE=80 MAXLENGTH=80></td>

</tr>
<tr>
<td>Project (if applicable)
<td><input TYPE=”text” NAME=”Project” VALUE=”” SIZE=80 MAXLENGTH=80></td>
</tr>
<tr>

<td>Project Leader
<td><input TYPE=”text” NAME=”Leader” VALUE=”” SIZE=80 MAXLENGTH=80></td>
</table><br><br><br>
<font size=+2><i><b>Account Information</i></b></font><br><br>
<table BORDER=”3″ BORDERCOLOR=”000000″ WIDTH=”830″ BGCOLOR=”FFDAB9″>
<tr>
<td>GSFC IP Address/Host Name</td>
<td><input TYPE=”text” NAME=”IP_HostName” VALUE=”” SIZE=80 MAXLENGTH=80></td>
</tr>
<tr>
<td valign=top><br><br>On which of the following machines do you wish to create a new account?</b>*
<td>
<table border bordercolor=”black” width =” 502″ cellspacing=0 cellpadding=0>
<tr bgcolor=FFEBCD>
<th> SGI </th>
<th> DEC Alpha </th>
<th> PC (Intel/Athlon) </th>
</tr>
<tr>
<td valign=top>
<select name=”SGI”>
<option value=”” name=”none”><pre>None</pre>
<option value=”dew” name=”dew”>dew
<option value=”land” name=”land”>land
<option value=”rain” name=”rain”>rain
</select>
</td>
<td valign=top>
<select name=”DECAlpha”>
<option value=”” name=”none”>none<br>
<option value=”air” name=”air”>air**<br>
<option value=”hydromet” name=”hydromet”>hydromet**
<br>

<option value=”water” name=”water”>water**
</select>
</td>
<td>
<select name=”PCs”>
<option value=”” name=”none”>none<br>
<option value=”dam” name=”dam”>dam<br>
<option value=”delta” name=”delta”>delta**
<br>
<option value=hsbserv name=”hsbserv”>hsbserv**<br>
<option value=”lshp” name=”lshp”>lshp<br>
<option value=”mere” name=”mere”>mere<br>
<option value=”nldas” name=”nldas”>nldas<br>
<option value=”nyanza” name=”nyanza”>nyanza<br>
<option value=”quench” name=”quench”>quench**
<br>
<option value=”spray” name=”spray”>spray<br>
<option value=”spring” name=”spring”>spring**<br>
<option value=”tarn” name=”tarn”>tarn<br>
<option value=”thirst” name=”thirst”>thirst**
<br>
</select>
</td>
</tr>
</table>
<tr>
<td>Desired User Name*</td>

<td><input TYPE=”text” NAME=”UserName” VALUE=”” SIZE=80 MAXLENGTH=80></td>
<tr>
<td>Alternate User Name*
<td><input TYPE=”text” NAME=”AlternateUserName” VALUE=”” SIZE=80 MAXLENGTH=80></td>
<tr>
<td>Please indicate the reasons for your request(s).</td>
<td><textarea NAME=”Reasons” MAXLENGTH=1000 ROWS=3 COLS=60>
</textarea>
</td>
</tr>
</table>
<br>
<br>
<font size=+2><i><b>Comments</i></b></font><br><br>
<table BORDER=”3″ BORDERCOLOR=”000000″ WIDTH=”830″ BGCOLOR=”FFDAB9″>

<tr>
<td>Please feel free to include any additional comments.</td>
<td><textarea NAME=”Comments” MAXLENGTH=1000 ROWS=8 COLS=60></textarea></td>
</table>
</tr>
</font>
<p>
<pre><font size=2 face=”Times New Roman”>* = required ** = dual cpu </pre></font>
<p>
<input type=”submit” “value”=”Submit Form”> <input TYPE=”reset” NAME=”reset”>
</form>
<br>
<br>
<br>
<hr color=”” size=5 width=90%>
</center><pre>
Please send any additional questions or comments to <a HREF=”MAILTO:megan@rainfall4.gsfc.nasa.gov”>Megan@rainfall4.gsfc.nasa.gov</a>
Responsible NASA Official: <A HREF=”mailto:houseri@hsb.gsfc.nasa.gov”>Dr. Paul Houser</A>
This site maintained by: <A HREF=”mailto:sambrin@hsb.gsfc.nasa.gov”>Sam Brin</A>
Goddard Space Flight Center
Greenbelt, MD 20711<BR>
<a href=”http://www.gsfc.nasa.gov/gsfc/usage2.htm”>NASA SECURITY AND PRIVACY STATEMENT</a></font>
<br>
<I>NASA IT Security <a href=”http://neptune.gsfc.nasa.gov/~brianc/ITsecure.html”>Warning Banner</a>
</pre>
</html>
END_OF_TEXT

to post a comment
JavaScript

1 Comments(s)

Copy linkTweet thisAlerts:
@damainman77authorJul 10.2003 — Never mind......I solved my own problem.

I can't believe I wrote that long post just because of a missing "}".
×

Success!

Help @damainman77 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.1,
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,
)...