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

multiple buttons on a form

P: n/a
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
Share this Question
Share on Google+
2 Replies


P: n/a
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

P: n/a
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.