Reply
submit button
Old 05-09-2006, 05:26 AM submit button
Novice Talker

Posts: 7
iv got a form with a sumbit button at bottom.at the momment when this button is clicked a window will pop up stating if any of the fields are completed incorrectly.if they are correct id like the button to link to confirmaiton/thankyou page but not link if incorrect. i got it working where the pop up messages work but when i try to link to the thnakyou page it links regardless of whether the fields are correcly filled in or not.

code:


Attach Code
<input type="submit" value="Submit" onClick="MM_validateForm('name','','R','email','', 'NisEmail','comments','','R');return document.MM_returnValue">
pellio is offline
Reply With Quote
View Public Profile
 
When You Register, These Ads Go Away!
     
Old 05-09-2006, 10:53 AM Re: submit button
funkdaddu's Avatar
Web Design Snob

Posts: 636
I'd have to see the functions, but basically have the validation form return either true, or return false and display an error. Then have the form setup to onsubmit="return yourValidationFunction()". if the function returns true it will finish the form, otherwise it will no go through.

Here is a simple example:
HTML Code:
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">

<html>

	<head>
		<meta http-equiv="content-type" content="text/html;charset=iso-8859-1">
		<title>Untitled Page</title>
		<script type="text/javascript"><!--
function check() {
	if (document.FormName.textfieldName.value != "") {
		return true;
	} else {
		alert("Please Fill in all fields");
		return false;
	}
}
//-->
</script>
	</head>

	<body bgcolor="#ffffff">
		<form id="FormName" action="" method="get" name="FormName" onsubmit="return check();">
			<input type="text" name="textfieldName" size="24"> <input type="submit" name="submitButtonName">
		</form>
		<p></p>
	</body>

</html>

Last edited by funkdaddu : 05-09-2006 at 10:58 AM.
funkdaddu is offline
Reply With Quote
View Public Profile Visit funkdaddu's homepage!
 
Old 05-09-2006, 07:41 PM Re: submit button
Novice Talker

Posts: 13
Location: Vancouver, BC
It works like this:

if the <form> tag has an "onsubmit" attribute, e.g.,

<form action="mylink.htm" onsubmit="checkMyForm()">

when the form is submitted, that onsubmit function (i.e., checkMyForm() in this example) will be executed. If this function returns a false value, the submission will be immediately aborted. Otherwise, continue the submission.

So in Funkdaddu's example, let's add the form submission url in the "action" attribute to complete it.
__________________
Visit my startup - Tooldle.com: $0 Web Plugin Tools for Web Designer
gumlor is offline
Reply With Quote
View Public Profile
 
Reply     « Reply to submit button
 

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.12218 seconds with 13 queries