Ok, I understand that. Thanks for the explanation. So it almost sounds
like I need to either have the events external to the tags or else I
need some code to evaluate the javascript in the tags (I found a pure
javascript example). But where would I put that code? In my main
page or inside the Ajax rendered view? Hmmm... maybe it doesn't
matter.
I think from my experiments I determined that code inside the <script>
tags was getting evaluated. But why isn't the $javascript->link
('filename') tag getting loaded I wonder?
On Jun 10, 6:27 pm, brian <[email protected]> wrote:
> On Wed, Jun 10, 2009 at 4:02 PM, Nancy<[email protected]> wrote:
>
> > Something seems to happen when you have javascript embedded in an ajax
> > rendered view and it is getting me confused!
>
> > I have this line at the top, it works when I call the view directly,
> > but doesn't seem to do anything when ajax renders the view:
>
> > <?= $javascript->link('clearSelect'); ?>
>
> > I see the alerts when the page is loaded directly but not through
> > ajax. The function works ok when loaded directly but not through
> > ajax. I'm using Protype and Ajax.
>
> > ====== clearSelect.js ==============
> > alert("hello!");
> > function unselectAll(ele)
> > {
> > alert(ele);
> > var obj=$(ele);
> > for (var i=0; i < obj.options.length; i++)
> > {
> > obj.options[i].selected = null;
> > }
> > }
> > =============================
>
> > I've also run into this issue when I have buttons and things on my
> > form I try to put some Javascript on, and they just don't work. I've
> > googled for an answer and realize that perhaps events aren't getting
> > hooked up but I'm not knowledgeable enough to figure out on my own how
> > to address that. So any specifics would be hugely appreciated! And
> > it looks like my javascript source file isn't being included at all.
>
> No, it is not. You have to understand what an AJAX request is, and
> what your javascript function is doing with the result. In your case,
> the view is being rendered by Cake into an HTML block which, when sent
> back to the client, is inserted into the DOM. A javascript include is
> not going to work because the tag will not be evaluated.
>
> It's a similar situation for event handlers. When the HTML chunk is
> inserted int the DOM, if there's no instruction to evaluate the page
> again in order to register event handlers you're not going to get the
> expected results. I use jQuery, not Prototype, so I can't give you any
> specifics to deal with that.
--~--~---------~--~----~------------~-------~--~----~
You received this message because you are subscribed to the Google Groups
"CakePHP" group.
To post to this group, send email to [email protected]
To unsubscribe from this group, send email to
[email protected]
For more options, visit this group at
http://groups.google.com/group/cake-php?hl=en
-~----------~----~----~----~------~----~------~--~---