www.webdeveloper.com
Results 1 to 6 of 6

Thread: Form w/ 2 buttons - which was pressed

  1. #1
    Join Date
    Jun 2005
    Posts
    86

    Exclamation Form w/ 2 buttons - which was pressed

    I have a form which has 2 buttons that can be pressed (New and update). Both should trigger the form submit after changing the value of a hidden field in the form. Is there a way to use a single function to fill in the value by determining which button was pressed, or do I have to write 2 different function with the same basic code?


    Chris

  2. #2
    Join Date
    Apr 2003
    Location
    Netherlands
    Posts
    21,654
    The name/value pair of the clicked button will be passed to the server script.

  3. #3
    Join Date
    Jan 2009
    Location
    paris,france
    Posts
    14
    If your user clicks on <input type="submit" name="fooButton" value="foo"/>, then the request will include the parameter "fooButton=foo", similarly for any other submit button in the same form ... so theoretically you don't need any other client-side code to determine which button was pressed.

  4. #4
    Join Date
    Jun 2005
    Posts
    86
    Thanks, I'm not sure why, but I'm still not getting what I think I should. I am using action="post" in my form. Can someone please look at this code:

    dim newUpdate
    if Request.Form("new")<>null then
    //Set up blank form for entering data
    newUpdate = "new"
    elseif Request.Form("update")<>null then
    //Call the Update query on the database with the updated values
    newUpdate = "update"
    else
    //Display the current item
    end if

    I am using VBScript in case you're wondering. When I click the "new" or the update button, and display the value of newUpdate, I get newUpdate=

    Chris

  5. #5
    Join Date
    Apr 2003
    Location
    Netherlands
    Posts
    21,654
    If your buttons have these name and value the value will be received
    Code:
    <button type="submit" name="submit" value="new">new</button>
    <button type="submit" name="submit" value="update">update</button>

  6. #6
    Join Date
    Jun 2005
    Posts
    86

    Smile

    OK, thanks for the help. I got it working now.

Thread Information

Users Browsing this Thread

There are currently 1 users browsing this thread. (0 members and 1 guests)

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
HTML5 Development Center



Recent Articles