SitePoint Sponsor

User Tag List

Results 1 to 3 of 3
  1. #1
    SitePoint Guru JoePrice's Avatar
    Join Date
    Jan 2002
    Location
    UK
    Posts
    673
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    How to check name of submit button when clicked?

    Hi guys

    I've got a form which has a submit button, when this button is pressed it calls a javascript function.

    I need to be able to find out the name of the button which is pressed when the function is called, can anyone suggest a way to find this out?

    so in normal speak, within the function i'd have

    if (button A has been pressed){
    then do this
    }


    many thanks

  2. #2
    SitePoint Guru JoePrice's Avatar
    Join Date
    Jan 2002
    Location
    UK
    Posts
    673
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    ok i've solved it, simple really
    just passed another variable to the function stating what button it is,
    duh.

  3. #3
    SitePoint Enthusiast
    Join Date
    Nov 2006
    Posts
    71
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Use something like...

    Code:
    function myFunction(buttonPressed)
    {
       if (buttonPressed == 'buttonA')
       {
          //stuff
       }
    
       //etc.
    }
    and

    Code:
    <input type="button" name="buttonA" onclick="myFunction(this.name);" />


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
  •