/    Sign up×
Community /Pin to ProfileBookmark

form required fields not working

Hi;
I hope someone can offer some assistance. I have a form that is supposed to send up an alert if the fields are not filled in. This form information, when submitted, goes to a Lotus Notes database. Can someone please tell me if I have the code in the right spots?
Thank you in advance for any help.

<SCRIPT LANGUAGE=”JavaScript”>
<!– Begin
function checkinput() {
if (document.register.FIRST_NAME.value.length < 1){
alert(“Please fill in a Name”);
document.register.FIRST_NAME.focus();
return false;
}
if (document.register.LAST_NAME.value.length < 1){
alert(“Please fill in an address”);
document.register.LAST_NAME.focus();
return false;
}
if (document.register.HOME_PHONE.value.length < 1){
alert(“Please fill in a City”);
document.register.HOME_PHONE.focus();
return false;
}
if (document.register.STATE_1.value.length < 1){
alert(“Please fill in a State”);
document.register.STATE_1.focus();
return false;
}
if (document.register.COUNTRY_1.value.length < 1){
alert(“Please fill in a Country”);
document.register.COUNTRY_1.focus();
return false;
}
if (document.register.EMAIL.value.length < 1){
alert(“Please fill in an email address”);
document.register.EMAIL.focus();
return false;
}
if (document.register.CITY.value.length < 1){
alert(“Please Select a product you purchased”);
document.register.CITY.focus();
return false;
}
if (document.register.PRIMARY_ADDR_1.value.length < 1){
alert(“Please Type in a Serial Number of product”);
document.register.PRIMARY_ADDR_1.focus();
return false;
}
if (document.register.PositionWanted.value.length < 1){
alert(“Please Type in Date Purchased”);
document.register.PositionWanted.focus();
return false;
}
return true;
}
// End –>
</script>

<TABLE border=”0″ bgcolor=”#FFFFFF” cellpadding=”0″ cellspacing=”0″ ID=”Table3″>
<TR valign=top>
<TD width=600>
<div align=”justify”>
<!– InstanceBeginEditable name=”solutionsbody” –>
<form action=”/cgi-bin/jobs.pl” method=”post”>
<input type=”hidden” name=”recipient” value=”[email protected]” />
<p><br />
</p>
<table width=”100%” border=”1″ cellspacing=”0″ cellpadding=”2″ bordercolor=”#D9D9D9″ bordercolorlight=”#D9D9D9″ bordercolordark=”White”>
<tr>
<td width=”20%” class=”contact”>First Name*</td>
<td><input maxlength=”64″ size=”45″ name=”FIRST_NAME” /></td>
</tr>
<tr>
<td class=”contact”>Middle Initial</td>
<td><input maxlength=”1″ size=”3″ name=”MIDDLE_NAME” /></td>
</tr>
<tr>
<td class=”contact”>Last Name*
</td>
<td><input maxlength=”64″ size=”45″ name=”LAST_NAME” /></td>
</tr>
<tr>
<td class=”contact”>Home Phone*</td>
<td><input maxlength=”20″ size=”45″ name=”HOME_PHONE” />
&nbsp;
<input type=”radio” checked=”checked” value=”1″ name=”PREFERRED_PHONE” />
Preferred Contact</td>
</tr>
<tr>
<td class=”contact”>Cell Phone</td>
<td><input maxlength=”20″ size=”45″ name=”CELL_PHONE” />
&nbsp;
<input type=”radio”
value=”3″ name=”PREFERRED_PHONE” />
Preferred Contact</td>
</tr>
<tr>
<td class=”contact”>E-mail*
</td>
<td><input maxlength=”128″ size=”45″ name=”EMAIL” /></td>
</tr>
<tr>
<td class=”contact”>Address*</td>
<td><input maxlength=”128″ size=”45″ name=”PRIMARY_ADDR_1″ /></td>
</tr>
<tr>
<td class=”contact”>&nbsp;</td>
<td><input maxlength=”128″ size=”45″ name=”PRIMARY_ADDR_2″ /></td>
</tr>
<tr>
<td class=”contact”>City*
</td>
<td><input maxlength=”128″ size=”45″ name=”CITY_1″ /></td>
</tr>
<tr>
<td class=”contact”>State*</td>
<td><input maxlength=”128″ size=”45″ name=”STATE_1″ /></td>
</tr>
<tr>
<td class=”contact”>Zip/Postal Code*
</td>
<td><input maxlength=”10″ size=”45″ name=”ZIP_1″ />
</td>
</tr>
<tr>
<td class=”contact”>Country</td>
<td><input maxlength=”128″ size=”45″ name=”COUNTRY_1″ /></td>
</tr>
<tr>
<td colspan=”2″ class=”contact2″><br />
Resume Text (Text only, no HTML)*</td>
</tr>
<tr>
<td colspan=”2″ class=”contact2″><textarea name=”RESUME” rows=”15″ wrap=”hard” cols=”60″></textarea>
</td>
</tr>
</table>
<p>Thank you very much! &nbsp
<input type=”submit” value=”submit” />
<input type=”reset” value=”clear” />
</p>
</form>
<p>&nbsp;</p>

<p>&nbsp;</p>
<div class=”leftlink” align=”right” valign=”top”></div>
<!– InstanceEndEditable –></div>

</TD>
</TR>
</TABLE>
</TD>
</TR>

<TR>
<TD colspan=2>
<BR>

</body>
<!– InstanceEnd –></html>

to post a comment
JavaScript

5 Comments(s)

Copy linkTweet thisAlerts:
@CharlesAug 21.2006 — Here's a working example that should get you started:[code=html]<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01//EN"
"http://www.w3.org/TR/html4/strict.dtd">
<html lang="en">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1">
<meta name="Content-Script-Type" content="text/javascript">
<meta name="Content-Style-Type" content="text/css">
<title>Example</title>

<script type="text/javascript">
function check (f) {
var e, i = 0
while (e = f.elements[i++]) {
if (e.type == 'text' && !/S/.test (e.value)) {
alert ('Please, field "' + e.previousSibling.data + '" is required.')
e.focus()
return false
}
}
}
</script>

<style type="text/css">
form {margin:auto; width:10em}
label, button {display:block; margin:1em auto}
</style>

</head>
<body>
<form action="some-script.pl" onsubmit="return check (this)">
<fieldset>
<legend>Example</legend>
<label>Name <input></label>
<label>Rank <input></label>
<label>Serial number <input></label>
<button type="submit">Submit</button>
</fieldset>
</form>
</body>
</html>[/code]
Copy linkTweet thisAlerts:
@bufhalauthorAug 21.2006 — Thanks for the reply.

I am trying to understand, if I put your JS code in the head section instead of the JS I have, that should create the alerts?
Copy linkTweet thisAlerts:
@bufhalauthorAug 21.2006 — Still goes to "jobs.pl" Perl script Thank you page. It does not send up a alert when the fields are missing information....
Copy linkTweet thisAlerts:
@CharlesAug 21.2006 — Thanks for the reply.

I am trying to understand, if I put your JS code in the head section instead of the JS I have, that should create the alerts?[/QUOTE]
There's a bit more to it than that. Study my example carefully. Or better yet, start with my example exactly as it is and change it slowly according to your needs - every step along the way checking to make sure that it works.
Copy linkTweet thisAlerts:
@KorAug 21.2006 — Still goes to "jobs.pl" Perl script Thank you page. It does not send up a alert when the fields are missing information....[/QUOTE]
Charles's example just drives you to the [I]dynamic[/I] way to handle the elements. The code should be as independent of the numbers/ids/names way of access the elements as it could be. The reference by a [B]general type[/B], the [B]root start[/B] and [B]loop[/B] method should be your best friends.

What is it what you have not understood in Charles code? What does not suit?
×

Success!

Help @bufhal 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.20,
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: @AriseFacilitySolutions09,
tipped: article
amount: 1000 SATS,

tipper: @Yussuf4331,
tipped: article
amount: 1000 SATS,

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