Hello and welcome to our community! Is this your first visit?
Enjoy an ad free experience by logging in. Not a member yet? Register.
Results 1 to 2 of 2
  1. #1
    Regular Coder mlse's Avatar
    Join Date
    Mar 2005
    Thanked 19 Times in 18 Posts

    How can I find out which submit button has been pressed?

    Hi all,

    Consider the following function:

    function form_getvars(formobj)
      var getvars = {};
      //Process the form elements.
      for (i=0; i<formobj.elements.length; i++)
        getvars[formobj.elements[i].name] = element_getvalue(formobj.elements[i]);
      return getvars;
    Where formobj is the form object obtained from document.forms within which a submit button has been pressed.

    So ... is there any way that formobj knows which of it's submit buttons has been pressed? Or will I need to pass the information in separately from the webpage?

    EDIT: Each submit button within each form has a unique name attribute.
    Last edited by mlse; 05-27-2009 at 11:25 AM.
    Die Welt ist ein Irrenhaus und hier ist die Zentrale!

  • #2
    New to the CF scene
    Join Date
    May 2009
    Thanked 0 Times in 0 Posts

    what button/.

    struggling with the same problem i stumbled upon this function. It works fine if u put it in ur form element.

    function getTarget(e) {
    var targ;
    if (!e) var e = window.event;
    if (e.target) targ = e.target;
    else if (e.srcElement) targ = e.srcElement;
    if (targ.nodeType == 3) // defeat Safari bug
    targ = targ.parentNode;

    return targ;

    call it like: <form onclick="getTarget(event)">
    Last edited by destMedia; 05-28-2009 at 01:21 PM. Reason: forgot:


    Posting Permissions

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