By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
459,729 Members | 1,370 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 459,729 IT Pros & Developers. It's quick & easy.

multiple submit buttons

P: 52
hi !
how can i use multiple submit buttons in the same form

i want to pass form values to different pages depending on which of the two submit button is clicked...
Mar 27 '09 #1
Share this Question
Share on Google+
7 Replies

P: 52
well i achieved that by using this code i found :

Expand|Select|Wrap|Line Numbers
  1. <SCRIPT language="JavaScript">
  2. function OnSubmitForm()
  3. {
  4.   if(document.pressed == 'Insert')
  5.   {
  6.    document.myform.action ="insert.html";
  7.   }
  8.   else
  9.   if(document.pressed == 'Update')
  10.   {
  11.     document.myform.action ="update.html";
  12.   }
  13.   return true;
  14. }
  15. </SCRIPT>
  18. <FORM name="myform" onSubmit="return OnSubmitForm();">
  20. <INPUT TYPE="SUBMIT" name="Operation" onClick="document.pressed=this.value" VALUE="Insert">
  22. <INPUT TYPE="SUBMIT" name="Operation" onClick="document.pressed=this.value" VALUE="Update">
  24. </FORM> 
now the problem is i need to call the validate function as well OnClick
how do i get around this
Mar 27 '09 #2

Expert 2.5K+
P: 3,405
Expand|Select|Wrap|Line Numbers
  1. <INPUT TYPE="SUBMIT" name="Operation" onClick="validate();document.pressed=this.value" VALUE="Update">
You can also put all of that functionality within the validate function. This is really more of a javascript question, if you are going to keep the thread going, we should move it to that forum now.

Mar 27 '09 #3

P: 52
well i tried didn't work...
yups, please move it....
Mar 27 '09 #4

P: 52
Expand|Select|Wrap|Line Numbers
  1. onsubmit="return (onsubmit() && validate(this));"
i used this for that..........
Mar 30 '09 #5

Expert Mod 15k+
P: 16,027
You should avoid using reserved words, e.g. onsubmit for function names. Some browsers may start complaining. You could also call the onsubmitform function within validate(). There's also no need to return from the function because it always returns true.
Mar 31 '09 #6

P: 52
writing onsubmit within validate didn't work for me... don't know why..
other points noted...
Mar 31 '09 #7

Expert Mod 15k+
P: 16,027
In validate(), just before return true at the end, just add:
Expand|Select|Wrap|Line Numbers
  1. OnSubmitForm();
  2. return true;
then your onsubmit event would be simply:
Expand|Select|Wrap|Line Numbers
  1. <form ... onsubmit="return validate(this);">
(you could always avoid this too and use unobtrusive JavaScript, of course).
Mar 31 '09 #8

Post your reply

Sign in to post your reply or Sign up for a free account.