469,326 Members | 1,590 Online
Bytes | Developer Community
New Post

Home Posts Topics Members FAQ

Post your question to a community of 469,326 developers. It's quick & easy.

Required fields?

I'm trying to write a code that will verifiy that each field was fill in. And if not it would return with and error message. Can someone help with this, here is my code so far:

[HTML]<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN">
<html>
<!-- Created with the CoffeeCup HTML Editor 2007 -->
<!-- http://www.coffeecup.com/ -->
<!-- Brewed on 2/18/2008 4:33:53 PM -->
<head>
<title>Customer Information</title>
</head>
<head>
<script type="text/javascript">
function validate_required(field,alerttxt)
{
with (field)
{
if (value==null||value=="")
{alert(alerttxt);return false;}
else {return true}
}
}function validate_form(thisform)
{
with (thisform)
{
if (validate_required(email,"Email must be filled out!")==false)
{email.focus();return false;}
}
}
</script>
</head>
<body>
<form action="submitpage.htm" onsubmit="return validate_form(this)"
method="post">

<form method="post" action="button.html">
First name:
<input type="text" name="firstname" size="20">
<br>
Last name:
<input type="text" name="lastname" size="20">
<br>
Email Address:
<input type="text" name="emailaddress" size="70">
<br>
Address:
<input type="text" address="address" size "50">
<br>
City:
<input type="text" city="city" size="20">
<br>
State:
<input type="text" state="state" size="2">
<br>
Zip Code:
<input type="text" zip code="zipcode" size="5">
<br>
<input type="submit" value="Submit">
</form>
</body>
</html>[/HTML]
Feb 22 '08 #1
2 1212
hsriat
1,654 Expert 1GB
What is this line for?

<form method="post" action="button.html">
Feb 22 '08 #2
acoder
16,027 Expert Mod 8TB
ghostrider, please enclose your posted code in [code] tags (See How to Ask a Question).

This makes it easier for our Experts to read and understand it. Failing to do so creates extra work for the moderators, thus wasting resources, otherwise available to answer the members' questions.

Please use [code] tags in future.

Thanks!
Feb 22 '08 #3

Post your reply

Sign in to post your reply or Sign up for a free account.

Similar topics

5 posts views Thread by Lorenzo Bolognini | last post: by
2 posts views Thread by Cliff R. | last post: by
2 posts views Thread by bufbec1 | last post: by
3 posts views Thread by Orchid | last post: by
7 posts views Thread by Tom van Stiphout | last post: by
1 post views Thread by CARIGAR | last post: by
reply views Thread by mdpf | last post: by
reply views Thread by harlem98 | last post: by
reply views Thread by listenups61195 | last post: by
By using this site, you agree to our Privacy Policy and Terms of Use.