Reply
Force Form to be Complete before Submission
Old 07-07-2005, 09:41 PM Force Form to be Complete before Submission
Super Talker

Posts: 116
I think i can do this in Javascript, (if not, point me to the right script), but how do you make it so that when a user presses the submit button on an html form, the script checks to make sure all the inputs have values before sending it to the action=""? Example: When signing up for a membership and you only enter your password once and forget to "verify" it, how does it create the alert() and say you need to fill in that field?
nasaboy007 is offline
Reply With Quote
View Public Profile Visit nasaboy007's homepage!
 
When You Register, These Ads Go Away!
Old 07-08-2005, 06:24 AM
onlyplace4's Avatar
Extreme Talker

Posts: 159
Location: Skegness, Lincolnshire, England
A function similar to that below will do it:
Code:
<script language="JavaScript">
function sub_check() {
	d = document.newsletter;
	if (d.email.value == "") { alert("Please enter an email address"); return(false) }
	URL = "subscribe.php?email="+e;
	window.location = URL;
}
</script>
You will, of course, need to change the form and field names to suit those you have used, and don't forget to use an opening <form> tag in the form of
Code:
<form action='' name='newsletter' id='newsletter' onSubmit='sub_check(); return(false)'>
Notice that the action is left blank in the form as the JavaScript actually takes care of that for you.

As Submit buttons can sometimes be a pain in the a** I always tend to use an image in the form:
Code:
<img src='images/subscribe.jpg' width='84' height='34' border='0' onClick='sub_check()'>
In case you are wondering why the routine is included in the <form> twice, this is done to ensure that people pressing the return key rather than clicking on the submit button are also sent via the error cheching routine.

I hope that clears things up for you.
onlyplace4 is offline
Reply With Quote
View Public Profile Visit onlyplace4's homepage!
 
Reply     « Reply to Force Form to be Complete before Submission
 

Thread Tools

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

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




   
RSS Feed  Feeds: RSS   JS   XML
RSS Feed  Feeds for this forum: RSS   JS   XML

 


Page generated in 0.12350 seconds with 12 queries