473,549 Members | 2,726 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

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="action 1()">

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

OR

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

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

So which is the appropriate way? please advise. thanks!!
Jul 23 '05 #1
2 2095
Matt wrote on 06 jul 2004 in comp.lang.javas cript:
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="action 1()">

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

OR

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

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

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


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

If you use the submit-button then I would use

<form action="main.as p" 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("a ctions")="actio n2" then response.redire ct "act2.asp"

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

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

<form onsubmit="retur n myAction()" action="main.as p" 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="action 1()">

OR

<INPUT TYPE="SUBMIT" NAME="action1" VALUE="Return to Main Search
Page" onClick="action 1()"> 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="action 1()">

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 thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

2
1839
by: Matt | last post by:
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"...
2
3130
by: Jeff | last post by:
I'm trying to create a dynamic form that can have multiple groups of radio buttons (each group has two buttons) with the same name. Essentially, the form allows a user to enter as many names as they want. If they need to add more, they click an "add name" button and the javascript inserts another row of input boxes. Each row should have...
0
2686
by: misscrf | last post by:
I am currently working on a database, in 3rd normal form, which is for candidates who apply for a job with the law firm that I workd for. My issue is with good form design. I have a main form. Then I have 3 pages on a tab control ( 4 if the type of candidate validates that is is to be shown) Each page has a subform. The subforms can...
3
2552
by: D. Shane Fowlkes | last post by:
Sorry for the length of this post. I have created a rather complex form which has a header/line item (parent and child records) structure. It's for an intranet. A screenshot can be seen here: http://www.drpt.virginia.gov/temp1.gif All the fields on this form have validation controls on them so they can not submit the form unless all...
8
579
by: TJS | last post by:
what are folks doing to get around limitation of one server form per page ?
7
3091
by: Siv | last post by:
Hi, I have an MDI application that uses a generic "ShowPage" routine in a module that is called when I want to display a child form. The basic idea is that in the module I have declared each form as follows: Friend F0 As frmMain Friend F1 As frmStart Friend F2 As frmSearch Then in my ShowPage routine (which is passed a string "pageToShow"...
5
19999
by: Alex Maghen | last post by:
In ASPX 2.0 with MasterPages and all that, my entire page only has one actual <FORM>. But there are several different sections of the page that provide what are functionally separate forms with separate Submit buttons. In basic HTML, I can have multiple forms on a page and the browser knows that if any of the fields for Form A have the...
5
14107
by: c676228 | last post by:
Hi everyone, my colleagues are thinking about have three insurance plans on one asp page: I simplify the plan as follow: text box:number of people plan1 plan2 plan3
4
2070
by: ApexData | last post by:
I have a continuous form that has Allow- Add/Edit/Del set to False, so that the form is in View mode only. I have New/Edit/Del buttons in the form header. My New & Edit buttons work as a like. My Del button works great also, but for one record at a time only. In ViewOnly mode, the user is able to highlight a single record to delete...
2
6933
by: 6afraidbecause789 | last post by:
Hi - Has anyone ever used toggle buttons to select items in a listbox? I'd like to put about 24 toggle buttons on an unbound form that select or deselect items in a multiple select listbox. I've come across a way to set the listbox value to only 1 at a time, but need multiple toggle buttons to be on their corresponding listbox item values...
0
7451
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language...
0
7960
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that...
1
7475
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For...
0
7812
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the...
0
6048
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then...
0
5089
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert...
0
3501
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in...
0
3483
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
0
766
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating...

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.