Free Web Hosting Forum
(#1 (permalink))
Old
kei's Avatar
kei kei is offline
Senior Member
kei is an unknown quantity at this point
 
Posts: 229
Join Date: Jun 2010
Default submit button onClick problem - 09-21-2010, 08:57 PM

[first i would like to apologize for making so many topics an soon after answering them myself]

So, i have a submit button that submits a form, the page it action=""'s to checks what button was pressed and does said function. the problem is, i need to run a validate() (JS) function when the button is pressed and only submit if the function returns successful.
if i put:
Code:
<input type="submit" name="signup" value="signup" onClick="validate()"/>
validate will run BUT the form will also be submitted anyways.
if i put:
Code:
<input type="button" name="signup" value="signup" onClick="validate()"/>
[p.s. "document.formname.submit();" is in the JS function]
in this case validate() will work and submit the form, BUT the action page does not see the button name eg. "if ($_POST["signup"] == 'signup')"
________
Vaporizer

Last edited by kei; 08-30-2011 at 06:08 AM.
Reply With Quote
Sponsored Links
(#2 (permalink))
Old
Junior Member
flips22738 is on a distinguished road
 
Posts: 7
Join Date: Nov 2010
Default 11-27-2010, 03:53 PM

I do it something like this.
Code:
<form id="signUpForm" method="post" action="handleFormSubmission.php" enctype="multipart/form-data">
-- form elements here --
<input type="button" value="signup" onclick="javascript:validate()"/>
</form>
Then the validate function looks something like this:
Code:
function validateForm()
{
	with(document.forms[0])
	{
		if(elements[1].value=="something_good");
		{
			submit();
		}
		else
		{
			elements[1].select();
		}
	}
}
Hope this helps.
Reply With Quote
(#3 (permalink))
Old
kei's Avatar
kei kei is offline
Senior Member
kei is an unknown quantity at this point
 
Posts: 229
Join Date: Jun 2010
Default 11-27-2010, 05:03 PM

no.
Quote:
i have a submit button that submits a form, the page it action=""'s to checks what button was pressed and does said function.
Quote:
in this case validate() will work and submit the form, BUT the action page does not see the button name eg. "if ($_POST["signup"] == 'signup')"
[i actually fixed this a long time ago though, so, no need to help =D]
________
Wellbutrin Side Effect

Last edited by kei; 08-30-2011 at 06:20 AM.
Reply With Quote
Reply

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 Off
Pingbacks are Off
Refbacks are Off

Forum Jump



Powered by vBulletin® Version 3.8.2
Copyright ©2000 - 2012, Jelsoft Enterprises Ltd.
Search Engine Friendly URLs by vBSEO 3.5.2
vBulletin Skin developed by: vBStyles.com