Code Newbie
News     Forums     Search     Members     Sign Up    

My Code Newbie
Username

Password

Articles/Snippets
ASP Classic
ASP.NET
C
C#
C++
HTML / CSS
Java
Javascript
Linux / BSD
Perl
PHP
Python
Ruby
SQL
VB 6
VB.NET

C.N. Friends
  Planet Rome

Link to Us!
Code Newbie
  Code Newbie
    forums
Old 01-26-2006, 01:22 PM   #1 (permalink)
Molly
Registered User
 
Molly's Avatar
 
Join Date: Sep 2005
Location: London
Posts: 8
Molly is on a distinguished road
How do I make fields mandatory on a form?

Hi I have a contact us form that emails me when submitted. However I want to make one of the fields mandatory so that if it isn't filled in it won't let you submit the form. However I not sure how to do it. Could anyone point me in the right direction?

Molly
Molly is offline   Reply With Quote
Old 01-26-2006, 03:40 PM   #2 (permalink)
sde
Moderator
 
sde's Avatar
 
Join Date: May 2002
Location: us.ca
Posts: 4,475
sde is on a distinguished road
Hi Molly,

Here's a quick little validation script. Let us know if you need any help with your own implementation.

HTML Code:
<script type="text/javascript" language="Javascript">
function validate( myform ) {
	if ( myform.email.value == "" ) {
		alert("Please enter your email address.");
		return false;
	}
	
	return true;
}
</script>

<form method="POST" action="mypage.php" onsubmit="return validate(this);">
<input type="text" name="email" value=""> <input type="submit">
</form>
sde is offline   Reply With Quote
Old 01-27-2006, 12:42 AM   #3 (permalink)
Molly
Registered User
 
Molly's Avatar
 
Join Date: Sep 2005
Location: London
Posts: 8
Molly is on a distinguished road
Brillaint thanks I will give it a go.
Molly is offline   Reply With Quote
Reply

Bookmarks

Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On


Similar Threads
Thread Thread Starter Forum Replies Last Post
Form questions JDE HTML, XML, Javascript, AJAX 2 10-29-2005 01:52 AM
can we make single form multiple submit buttons salmanjoo PHP 7 08-20-2005 07:44 AM
Passing Values from Popup Form to Main Form chrislopezz PHP 7 03-28-2005 12:45 PM
EMERGENCY: Dynamic form processing DavH27 PHP 8 10-27-2004 07:52 PM


All times are GMT -8. The time now is 10:13 PM.


Powered by vBulletin® Version 3.7.0
Copyright ©2000 - 2008, Jelsoft Enterprises Ltd.
Search Engine Optimization by vBSEO 3.0.0 RC8





Copyright © 2000-2008, Milano Interactive
Web Hosting provided by Portal 360 Web Hosting