1 Form using 2 Submit Buttons

Posted on 2004-11-23
Last Modified: 2010-04-25
I have a form and need to have 2 submit buttons on it and depending upon which button (both for updates) is pressed the database will update accordingly.
Dreamweaver won't allow this, and I don't know where to start.

Can someone point me in the right direction?
Question by:Benno2805
    LVL 19

    Expert Comment

    You can't have two submit buttons.

    What EXACTLY are you trying to do?
    LVL 1

    Author Comment

    It's information entered by the client and it can be modified or made inactive. Depending on which button is pressed, one will do the modifications, the other will make the record inactive both via Updates.
    LVL 1

    Author Comment

    OK, I've thought that it may be easier doing it with radio buttons and if RadioButton1 is active then 'do this update' if radionbutton2 is active then do this update...

    But I don't know how to put it in the code, especially since Dreamweaver puts in a lot of stuff you don't really need.

    LVL 48

    Assisted Solution

    by:Ryan Chong
    You need to have a form onsubmit event, where it will set to call a javascript function to check which radio button you have selected, and then determine what action (we can change the form's Action just before the posting) to take, clear?

    Post your code here if necessary, so that we can help you amend it.

    LVL 2

    Assisted Solution

    You could create 2 update 'command' pages, one for each button.  Each button would simply need to be a link to the correct command page.  Pass the parameters to each command page for the update via Request.Form. Have the command pages redirect back to the form page (or where ever you need the user to go).  You will need to add the Response.Redirect line to each command page manually.  To the user, this works virtually seamlessly.  

    LVL 10

    Accepted Solution

    There only needs to be one 'receiving' page - you can just have a value added to the form according to which button you press, to tell the receiving page what to do with the data. How about this:

    function doModify() {
    <form name="myForm" action="update.php" method="post">
    <input type="hidden" name="mod" id="mod" value="0"></input>
    <input type="submit" name="inactive" value="Make data inactive"></input>
    <input type="button" name="update" value="Update data" onclick="doModify();"></input>

    Then your receiving page (it could even loop back to this page if you wish) can be coded to do the update if the form variable mod=1, and deactivate it if mod=0.
    LVL 1

    Author Comment

    Thanks guys, I took a little bit of advice from each of you and i've come up with a clean, reliable solution.

    Thanks again.
    LVL 2

    Expert Comment

    That's great Benno2805.  Glad things worked out for you.


    Featured Post

    Highfive + Dolby Voice = No More Audio Complaints!

    Poor audio quality is one of the top reasons people don’t use video conferencing. Get the crispest, clearest audio powered by Dolby Voice in every meeting. Highfive and Dolby Voice deliver the best video conferencing and audio experience for every meeting and every room.

    Join & Write a Comment

    Suggested Solutions

    For those who don't know, Adobe Dreamweaver is a popular commercial web editor that enables you to design, build and manage complex websites. The editor is a WYSIWYG (What You See Is What You Get) web editor, which means that you can create your web…
    This article is very specific and is only intended to help if you are installing Dreamweaver 8 in a Windows 7 environment with Office 2007 installed.   I'm not sure why Microsoft tends to release OS' that should not be released but they do.  Windows…
    Excel styles will make formatting consistent and let you apply and change formatting faster. In this tutorial, you'll learn how to use Excel's built-in styles, how to modify styles, and how to create your own. You'll also learn how to use your custo…
    This demo shows you how to set up the containerized NetScaler CPX with NetScaler Management and Analytics System in a non-routable Mesos/Marathon environment for use with Micro-Services applications.

    746 members asked questions and received personalized solutions in the past 7 days.

    Join the community of 500,000 technology professionals and ask your questions.

    Join & Ask a Question

    Need Help in Real-Time?

    Connect with top rated Experts

    16 Experts available now in Live!

    Get 1:1 Help Now