Connecting Tech Pros Worldwide Help | Site Map

multiple submit buttons

Member
 
Join Date: Mar 2009
Location: India
Posts: 52
#1: Mar 27 '09
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...
thank's
Member
 
Join Date: Mar 2009
Location: India
Posts: 52
#2: Mar 27 '09

re: multiple submit buttons


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>
  16.  
  17.  
  18. <FORM name="myform" onSubmit="return OnSubmitForm();">
  19.  
  20. <INPUT TYPE="SUBMIT" name="Operation" onClick="document.pressed=this.value" VALUE="Insert">
  21.  
  22. <INPUT TYPE="SUBMIT" name="Operation" onClick="document.pressed=this.value" VALUE="Update">
  23.  
  24. </FORM> 
now the problem is i need to call the validate function as well OnClick
how do i get around this
jhardman's Avatar
Moderator
 
Join Date: Jan 2007
Location: logan, utah
Posts: 2,690
#3: Mar 27 '09

re: multiple submit buttons


Expand|Select|Wrap|Line Numbers
  1. <INPUT TYPE="SUBMIT" name="Operation" onClick="validate();document.pressed=this.value" VALUE="Update">
  2.  
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.

Jared
Member
 
Join Date: Mar 2009
Location: India
Posts: 52
#4: Mar 27 '09

re: multiple submit buttons


well i tried that..........it didn't work...
yups, please move it....
thank's...
Member
 
Join Date: Mar 2009
Location: India
Posts: 52
#5: Mar 30 '09

re: multiple submit buttons


Expand|Select|Wrap|Line Numbers
  1. onsubmit="return (onsubmit() && validate(this));"
  2.  
i used this for that..........
acoder's Avatar
Site Moderator
 
Join Date: Nov 2006
Location: UK
Posts: 14,581
#6: Mar 31 '09

re: multiple submit buttons


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.
Member
 
Join Date: Mar 2009
Location: India
Posts: 52
#7: Mar 31 '09

re: multiple submit buttons


hi
writing onsubmit within validate didn't work for me... don't know why..
other points noted...
thank's..
acoder's Avatar
Site Moderator
 
Join Date: Nov 2006
Location: UK
Posts: 14,581
#8: Mar 31 '09

re: multiple submit buttons


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).
Reply

Tags
asp, button, submit