Tycoon Talk
Become a Big fish!
The number 1 forum for online business!
Post topics, ask questions, share your knowledge.
Tycoon Talk is part of Freelancer.com - find skilled workers online at a fraction of the cost.

JavaScript Forum


You are currently viewing our JavaScript Forum as a guest. Please register to participate.
Login



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

Posts: 116
Trades: 0
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?
__________________


Please login or register to view this content. Registration is FREE

nasaboy007 is offline
Reply With Quote
View Public Profile Visit nasaboy007's homepage!
 
 
Register now for full access!
Old 07-08-2005, 07:24 AM
onlyplace4's Avatar
Extreme Talker

Posts: 159
Location: Skegness, Lincolnshire, England
Trades: 0
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.
__________________

Please login or register to view this content. Registration is FREE


Please login or register to view this content. Registration is FREE


Please login or register to view this content. Registration is FREE
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 Search this Thread
Search this Thread:

Advanced Search

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 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.23749 seconds with 12 queries