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)