Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations TouchToneTommy on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Unobtrusive Javascript and Submiting forms

Status
Not open for further replies.

RicksAtWork

Programmer
Nov 1, 2005
120
GB
I have a method addEvent which wires up events.

//Set default submit handler to always return false, and therefore not submit the form.
document.getElementById('Form1').onsubmit=function(){return false;}

//The following code points all submit events at the method EventKernal
addEvent(document.getElementById('Form1'), 'submit', EventKernal);

In the function EventKernal, I want to determine which button was pressed which caused the submission.

The following code will only return a reference to Form1.

How can I detremine which button was pressed?

function EventKernal(e)
{

//Get event object and source element

eventObject = (e)? e:event;

//IE
originalObject = e.srcElement;

//Mozilla
if(originalObject == null)
{
originalObject = e.target;
}

alert(originalObject.id);

return false;

}

 
How many such buttons do you have?

What does their HTML look like?

What do the parameters in your addEvent(...) call mean? Is the form being given an onsubmit call to "EventKernal()" or is the submit button on the form being given an onclick event of EventKernal() or ...


~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
O Time, Strength, Cash, and Patience! [infinity]
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top