/    Sign up×
Community /Pin to ProfileBookmark

Form Validation problems

Can someone help me with this, I am trying to get this form to validate the fields by checking to see the length of the valu within each field. I also need the form to email me the results. Its crude, and this is how its going to have to work. I am also having trouble with the radio buttons, how do i check to see if something is checked?

Thanks.

<script>
function confirmReset() {
var resetForm = confirm(“Are you sure you want to reset the form?”);
if (resetForm == true)
return true;
return false;
}

function validate() {
if (document.order.firstname.value.length < 2) {
alert(“Please enter your full first name.”);
return false;
}
if (document.order.lastname.value.length < 2) {
alert(“Please enter your full last name.”);
return false;
}
if (document.order.street.value.length < 5) {
alert(“Please enter your full street address.”);
return false;
}
if (document.order.city.value.length < 2) {
alert(“Please enter your full city name.”);
return false;
}
if (document.order.state.value.length < 2) {
alert(“Please enter your state.”);
return false;
}
if (document.order.zip.value.length < 5) {
alert(“Please enter your zip code.”);
return false;
}
if (document.order.phone.value.length < 7) {
alert(“Please enter your phone number.”);
return false;
}
if (document.order.email.value.length < 5) {
alert(“Please enter your email.”);
return false;
}
if (document.order.form.value.length < 1) {
alert(“Please enter your email.”);
return false;
}
return true;
}
</script>

<form name=”order” id=”order” onSubmit=”return validate(); action=”mailto:[email protected]” enctype=”text/plain” method=”POST” onReset=”return confirmReset();”>

<table border=”0″ width=”250″ cellspacing=”0″ cellpadding=”0″>
<tr>
<td width=”50%”><b>First Name:</b></td>
<td width=”50%”><input name=”firstname” id=”firstname”></td>
</tr>
<tr>
<td width=”50%”><b>Last Name:</b></td>
<td width=”50%”><input name=”lastname” id=”lastname”></td>
</tr>
<tr>
<td width=”50%”><b>Street Address:</b></td>
<td width=”50%”><input name=”street” id=”street”></td>
</tr>
<tr>
<td width=”50%”><b>City:</b></td>
<td width=”50%”><input name=”city” id=”city”></td>
</tr>
<tr>
<td width=”50%”><b>State:</b></td>
<td width=”50%”><input name=”state” id=”state” size=”3″></td>
</tr>
<tr>
<td width=”50%”><b>Zip:</b></td>
<td width=”50%”><input name=”zip” id=”zip” size=”10″></td>
</tr>
<tr>
<td width=”50%”><b>Phone:</b></td>
<td width=”50%”><input name=”phone” id=”phone”></td>
</tr>
<tr>
<td width=”50%”><b>Email:</b></td>
<td width=”50%”><input name=”email” id=”email”></td>
</tr>
<tr>
<td width=”50%” valign=”top”><b>Type of Form:</b></td>
<td width=”50%”>
<input type=”radio” name=”form” value=”form1″>Form1<br>
<input type=”radio” name=”form” value=”form2″>Form2<br>
<input type=”radio” name=”form” value=”form3″>Form3</td>
</tr>
<tr>
<td colspan=”2″><br><br><div align=”right”><input TYPE=”SUBMIT” VALUE=”Submit”>&nbsp;&nbsp;&nbsp;<input TYPE=”RESET”

VALUE=”Reset”></div></td>
</tr>
</table>

to post a comment
JavaScript

3 Comments(s)

Copy linkTweet thisAlerts:
@khalidali63May 30.2003 — Take a look at this form,and see if this validation helps you understand the conepts..

http://68.145.35.86/skills/javascripts/UltimateFormValidator.html
Copy linkTweet thisAlerts:
@mplutodh1authorMay 30.2003 — [i]Originally posted by khalidali63 [/i]

[B]Take a look at this form,and see if this validation helps you understand the conepts..

http://68.145.35.86/skills/javascripts/UltimateFormValidator.html [/B]
[/QUOTE]



Thanks I am going to have to take a closer look at it.
Copy linkTweet thisAlerts:
@mplutodh1authorMay 30.2003 — [i]Originally posted by Dave Clark [/i]

[B]For your radio buttons:



<input type="radio" name="form" value="form1">Form1<br>

<input type="radio" name="form" value="form2">Form2<br>

<input type="radio" name="form" value="form3">Form3



you better change the name. Each FORM element already has a property of [b]form[/b] and your use of the same name may cause conflicts.



[b]Dave[/b] [/B]
[/QUOTE]


Good call... didnt even think of that
×

Success!

Help @mplutodh1 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 6.2,
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: @meenaratha,
tipped: article
amount: 1000 SATS,

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

tipper: @AriseFacilitySolutions09,
tipped: article
amount: 1000 SATS,
)...