PDA

View Full Version : How can I find out which submit button has been pressed?


mlse
05-27-2009, 12:17 PM
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.

destMedia
05-28-2009, 02:20 PM
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;

//alert(targ);
return targ;
}

call it like: <form onclick="getTarget(event)">