On May 5, 11:52 am, Ugo <priv...@[EMAIL PROTECTED]
> wrote:
> >>> I have a situation where I have a button with an onclick event
> >>> containing a function and I need to append a function to that event.
> >>> For example, I have:
> >>> <button id="btn" onclick="func1(param);">The Button</button>
> >>> When the user clicks another button, I want to essentially have the
> >>> button above look like:
> >>> <button id="btn" onclick="func1(param);func2(param);">The Button</
> >>> button>
> >>> Is this possible?
>
> >> Yes
> >> e.g.
> >> <button id="btn2" onclick="do***ent.getElementById('btn').onclick =
> >> function(){ func1(param);func2(param); }">change</button>
>
> > Thank you for your quick and informative answer. However, I failed to
> > mention a very im****tant piece of the puzzle. The button to which I
> > need to add the new event is going to be created in the same onclick
> > event. I'm finding out in that case, javascript doesn't even
> > recognize the new component until the page refreshes. So, I can't do
> > this without changing the function that adds the button, which I'm not
> > allowed to do.
>
> > Oh well, I'll continue banging away at it.
>
> look if I understand...
>
> you have a button so:
> <button id="btn" onclick="func1(param);">The Button</button>
> and you want it becomes so:
> <button id="btn" onclick="func1(param);func2(param);">The
Button</button>
> after first click, is it right?
>
Sorry, that's not right.
What I have to begin with is button A only.
User clicks button A.
In the onclick event for button A I have a function that creates
button B. The function that creates button B attaches an onclick
event to button B. After button B is created (while still in the
onclick event handler) I need to add another function to button B's
onclick event.
Sorry if this isn't clear, but it's a strange requirement.
Thanks for trying to help.
> if so, and if you may append a function firstly:
> <button id="btn" onclick="func1(param);changeEvent(this)">
> The Button</button>
>
> function changeEvent(elem)
> {
> elem.onclick = function()
> {
> func1(param);func2(param);
> }
>
> }


|