List Info

Thread: How to get Signal.connect code rendered via .innerHTML replacement to work?




How to get Signal.connect code rendered via .innerHTML replacement to work?
country flaguser name
United States
2007-10-05 01:05:54
The Problem:
I have a button on a page that results in getting HTML back
from the
server which contains something like the following
(result['content']
(below) contains the following):


    <input src="/static/images/btn_left.png"
name="mybutton"
type="image" id="mybutton_id"
value="somevalue"
class="imagebutton">
    <script type="text/javascript">

        onclick_mybutton= function(e)
        {
            return myJavaScriptFunction(this.form,
target_id, e);
        }
        MochiKit.Signal.connect("mybutton_id",
"onclick",
onclick_mybutton);

    </script>

This is then rendered to the page via something like:
getElement(target_id).innerHTML = result['content'];

Now, I get everything rendered just fine (so I can see the
button
represented by btn_left.png)... however, the browser doesn't
execute
the new function (seen above) on click... .  I know the
above block of
code works fine as I have nearly identical blocks of code
hooked up to
other buttons that are rendered on the initial page load.

What am I missing here?  Does .innerHTML not render the HTML
in the
same way as the original page load (in other words, ignoring
the
Mochikit.Signal.connect.. call?)

Any help would be greatly appreciated.


--~--~---------~--~----~------------~-------~--~----~
You received this message because you are subscribed to the
Google Groups "MochiKit" group.
To post to this group, send email to mochikitgooglegroups.com
To unsubscribe from this group, send email to
mochikit-unsubscribegooglegroups.com
For more options, visit this group at http://
groups.google.com/group/mochikit?hl=en
-~----------~----~----~----~------~----~------~--~---


Re: How to get Signal.connect code rendered via .innerHTML replacement to work?
country flaguser name
United States
2007-10-05 05:28:11
On Oct 5, 7:05 am, John Lorance <john.lora...gmail.com> wrote:
> The Problem:
>         onclick_mybutton= function(e)
>         {
>             return myJavaScriptFunction(this.form,
target_id, e);
>         }
>
> Now, I get everything rendered just fine (so I can see
the button
> represented by btn_left.png)... however, the browser
doesn't execute
> the new function (seen above) on click... .

Not sure, but:

 - IIRC, 'this' in the context of the event handler is bound
to the
object that fired the event (your input). If not it's bound
to the
'onclick_mybutton' function. Either way, neither have a
'form'
attribute AFAICS.

 - where's target_id come from?


--~--~---------~--~----~------------~-------~--~----~
You received this message because you are subscribed to the
Google Groups "MochiKit" group.
To post to this group, send email to mochikitgooglegroups.com
To unsubscribe from this group, send email to
mochikit-unsubscribegooglegroups.com
For more options, visit this group at http://
groups.google.com/group/mochikit?hl=en
-~----------~----~----~----~------~----~------~--~---


Re: How to get Signal.connect code rendered via .innerHTML replacement to work?
user name
2007-10-05 09:24:02
On 10/4/07, John Lorance <john.lorancegmail.com> wrote:
>
> The Problem:
> I have a button on a page that results in getting HTML
back from the
> server which contains something like the following
(result['content']
> (below) contains the following):
>

innerHTML doesn't execute script. You could try something
like this:

var elem = getElement(target_id);
elem.innerHTML = result['content'];
var script_tags =
getElementsByTagAndClassName("script", null,
elem);
for (var i = 0; i < script_tags.length; i++) {
    eval(scrapeText(script_tags[i]));
}

I'm not sure if that works in all of the browsers, make sure
to give
it a try in the ones you care about.

-bob

--~--~---------~--~----~------------~-------~--~----~
You received this message because you are subscribed to the
Google Groups "MochiKit" group.
To post to this group, send email to mochikitgooglegroups.com
To unsubscribe from this group, send email to
mochikit-unsubscribegooglegroups.com
For more options, visit this group at http://
groups.google.com/group/mochikit?hl=en
-~----------~----~----~----~------~----~------~--~---


[1-3]

about | contact  Other archives ( Real Estate discussion Medical topics )