471,350 Members | 1,372 Online
Bytes | Software Development & Data Engineering Community
Post +

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 471,350 software developers and data experts.

multiple buttons on a form

The ASP page has multiple buttons, and when the user clicks different
buttons, it will submit the form data to different URLs.

My first approach was to use BUTTON type, and triggers javascript function
to submit the form data. However, it didn't work properly and I changed to
use SUBMIT type.

<INPUT TYPE="BUTTON" NAME="action1" VALUE="Return to Main Search Page"
onClick="action1()">

function action1()
{ //etc...
document.myform.action = "main.asp"
document.myform.submit();
}

OR

<INPUT TYPE="SUBMIT" NAME="action1" VALUE="Return to Main Search Page"
onClick="action1()">

function action1()
{ //etc...
document.myform.action = "main.asp"
}

So which is the appropriate way? please advise. thanks!!
Jul 23 '05 #1
2 1950
Matt wrote on 06 jul 2004 in comp.lang.javascript:
The ASP page has multiple buttons, and when the user clicks different
buttons, it will submit the form data to different URLs. My first approach was to use BUTTON type, and triggers javascript
function to submit the form data. However, it didn't work properly and
I changed to use SUBMIT type.

<INPUT TYPE="BUTTON" NAME="action1" VALUE="Return to Main Search Page"
onClick="action1()">

function action1()
{ //etc...
document.myform.action = "main.asp"
document.myform.submit();
}

OR

<INPUT TYPE="SUBMIT" NAME="action1" VALUE="Return to Main Search Page"
onClick="action1()">

function action1()
{ //etc...
document.myform.action = "main.asp"
}

So which is the appropriate way? please advise. thanks!!


There is no "appropriate way".
In programming you can have your personal preference.

If you use the submit-button then I would use

<form action="main.asp" method="post">
<input type="submit" name="actions" value="action1">
<input type="submit" name="actions" value="action2">

and have serverside ASP[vbs] find out what action you want to accomplish:

if request.form("actions")="action2" then response.redirect "act2.asp"

==============

but clientside coding is possible [to prohibit submission, par example]:

<form onsubmit="return myAction()" action="main.asp" method="post">
<input type="submit" name="actions" value="action1" onclick="a=1">
<input type="submit" name="actions" value="action2" onclick="a=2">
<input type="submit" name="actions" value="action3" onclick="a=3">

where, when action() returns false, the submit will not be carried out:

function myAction()
// no submit if a=1
return (a!=1)
}

not tested

--
Evertjan.
The Netherlands.
(Please change the x'es to dots in my emailaddress)
Jul 23 '05 #2
Matt wrote:
The ASP page has multiple buttons, and when the user clicks
different buttons, it will submit the form data to different URLs.

My first approach was to use BUTTON type, and triggers javascript
function to submit the form data.
This is a fragile solution; where js is not available, does the form
do anything? This is generally best done server side.
it didn't work properly and I changed to use SUBMIT type.

<INPUT TYPE="BUTTON" NAME="action1" VALUE="Return to Main Search
Page" onClick="action1()">

OR

<INPUT TYPE="SUBMIT" NAME="action1" VALUE="Return to Main Search
Page" onClick="action1()"> So which is the appropriate way?


Since the button that does not do anything, I'd choose input
type="button", which has no default behavior. It looks like the form
just gives someone a new page, so a simple text link is probably best.
But if the form does something else, how about this?:

<INPUT TYPE="SUBMIT" NAME="action1"
VALUE="Return to Main Search Page" onClick="action1()">

Then use javascript to change the behavior, e.g., return false
onSubmit and do something else. That makes it transparent to the user.

--
Brian (remove ".invalid" to email me)
http://www.tsmchughs.com/
Jul 23 '05 #3

This discussion thread is closed

Replies have been disabled for this discussion.

Similar topics

3 posts views Thread by D. Shane Fowlkes | last post: by
8 posts views Thread by TJS | last post: by
5 posts views Thread by Alex Maghen | last post: by

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.