SitePoint Sponsor

User Tag List

Results 1 to 3 of 3
  1. #1
    SitePoint Zealot
    Join Date
    Jul 2004
    Location
    england
    Posts
    114
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    Determine which button has been pressed?

    Hi

    I have one form, two submit buttons. I'm using ASP to find out which is pressed and then act accordingly and that is working fine.
    However, in the form I have an onsubmit handler, and within that javascript function I want to give the user a different alert based on the submit button pressed.

    However, I don't know how to find how which has been pressed using js, as nothing is "passed" to the js.... am I correct?
    Can this be done?

    Any help grateful! thanks!

  2. #2
    SitePoint Addict
    Join Date
    May 2004
    Location
    Europe
    Posts
    216
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Sure, no problem. This snippet should tell you the basic idea:
    Code:
    <form action="javascript:void 0" onsubmit="alert(this.whichButton)">
    <input type="submit" onclick="this.form.whichButton=1">
    <input type="submit" onclick="this.form.whichButton=2">
    </form>

  3. #3
    SitePoint Zealot
    Join Date
    Jul 2004
    Location
    england
    Posts
    114
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    that's really great code! thanks!


Bookmarks

Posting Permissions

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