How to pass a form element's event

D

donpro

Hi.

I'm using DOM to manage a HTML form and so I create listeners for my
form objects that run a function when fired. The function is of the
form:

function myfunction(e) {
var myElement = getSrcElement(e);
}

function getSrcElement(e) {
e = e || window.event;
return e && (e.target || e.srcElement);
}


Question: I've run in to a situation where I need to manually call
myfunction(e) within another fnction. How do I manually pass an
object's event? I don't even know how to create it.

Thanks,
Don
 
S

SAM

Le 12/30/08 6:02 PM, donpro a écrit :
Hi.

I'm using DOM to manage a HTML form and so I create listeners for my

Don't see any listener ...
form objects that run a function when fired.

what is a "form object" ?
The function is of the form:

function myfunction(e) {
var myElement = getSrcElement(e);
}

I suppose you expect to do something with 'myElement' further in same
function myfunction() ?
function getSrcElement(e) {
e = e || window.event;
return e && (e.target || e.srcElement);
}


Question: I've run in to a situation where I need to manually call
myfunction(e) within another fnction.

Describe the situation and what you want to get.

You cant click by JS. Except an input 'submit' or probably a 'button'.
(with name='myButton': document.myForm.myButton.click(); )
(with id='myButton': document.getElementById('myButton').click(); )
How do I manually pass an object's event?
I don't even know how to create it.

As I didn't understand what you mean ...
(what is and where 'to pass' an object's event ? which event ?)
 
R

RobG

Hi.

I'm using DOM to manage a HTML form and so I create listeners for my
form objects that run a function when fired.  The function is of the
form:

function myfunction(e) {
   var myElement = getSrcElement(e);

}

function getSrcElement(e) {
        e = e || window.event;
        return e && (e.target || e.srcElement);

That function might be better named getTarget, since there are many
more browsers that support the W3C's model than IE's proprietary
model.
}

Question: I've run in to a situation where I need to manually call
myfunction(e) within another fnction.  How do I manually pass an
object's event?  I don't even know how to create it.

I think you are looking for the DOM createEvent and it's sibling,
dispatchEvent:

<URL: http://www.w3.org/TR/DOM-Level-2-Events/events.html#Events-DocumentEvent-createEvent
IE uses createEventObject and fireEvent:

<URL: http://msdn.microsoft.com/en-us/library/ms536390(VS.85).aspx >


Search the archives for examples and restrictions, post again when you
hit trouble - I think you will. :)
 
B

Ben Amada

Question: I've run in to a situation where I need to manually call
myfunction(e) within another fnction.  How do I manually pass an
object's event?  I don't even know how to create it.

alert('Attention User: Please click the Submit button for me.);

(sorry, just some end of the year humor :)
 
J

Jeremy J Starcher

alert('Attention User: Please click the Submit button for me.);

(sorry, just some end of the year humor :)

In a Dilbert-style world, I've *seen* this.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,780
Messages
2,569,611
Members
45,276
Latest member
Sawatmakal

Latest Threads

Top