Hi,
It's probably a scoping problem. You can try it a couple different ways:

1) declare your "vars" outside the dom:load, like:

var chatButton, comments;

document.observe('dom:loaded', function() {
  chatButton = $('chatButton');
  comments = $('comment_box');
  chatButton.observe('click', function(event){
    alert("hello");
    comments.toggle();
  });
});

or, 2) use the extended version of your elements inside the dom:load, like:

document.observe('dom:loaded', function() {
  chatButton = $('chatButton');
  chatButton.observe('click', function(event){
    alert("hello");
    $('comment_box').toggle();
  });
});

Either approach should work, depending on whether or not you need access to
those "global variables" or not.

Let us know if this helps, or if you figured out another way around it!

Best Regards,
Ed C.


On Feb 10, 2008 9:27 AM, elduderino <[EMAIL PROTECTED]> wrote:

>
> can anyone spot a problem with this code...when a user clicks on the
> element with an id of chatButton it should toggle the element with an
> id of comment_box...but it doesn't. I have display: none set inline on
> the comment_box.....if i put an alert in where ive put the commented
> out alert("hello") in the code below what happens is the when i click
> the alert hello shows then when i click that the comment_box shows
> then the alert shows again and the comment box gets hidden?!?!?! Its
> like the toggle runs twice in one function....any ideas of what ive
> got wrong because i cannot spot it?
>
> document.observe('dom:loaded', function() {
> var chatButton = $('chatButton');
> var comments = $('comment_box');
> chatButton.observe('click', function(event){
> //alert("hello");
>    alert("hdfghfg");
>    comments.toggle();
>    })
> })
> >
>

--~--~---------~--~----~------------~-------~--~----~
You received this message because you are subscribed to the Google Groups "Ruby 
on Rails: Spinoffs" 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/rubyonrails-spinoffs?hl=en
-~----------~----~----~----~------~----~------~--~---

Reply via email to