I tried following Ryan Bates'' railscast on rjs tips (http://railscasts.com/episodes/45-rjs-tips) and apply his method of using if-else inside the rjs template, but can''t seem to get it to work. Basically, I''m trying to toggle the text on a link when it''s clicked (test.js.rjs): page << "if ($(''test_link'').value == ''one'' {" page.replace_html ''test_link'', ''two'' page << "} else {" page.replace_html ''test_link'', ''one'' page << "}" I believe I have the necessary view and controller code: <%= link_to_remote ''one'', :url => { :action => ''test'' } %> and def test respond_to do |format| format.js end end -- Posted via http://www.ruby-forum.com/. --~--~---------~--~----~------------~-------~--~----~ You received this message because you are subscribed to the Google Groups "Ruby on Rails: Talk" group. To post to this group, send email to rubyonrails-talk-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org To unsubscribe from this group, send email to rubyonrails-talk+unsubscribe-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en -~----------~----~----~----~------~----~------~--~---
On 19 Jan 2009, at 09:27, Shilo Ayalon wrote:> > I tried following Ryan Bates'' railscast on rjs tips > (http://railscasts.com/episodes/45-rjs-tips) and apply his method of > using if-else inside the rjs template, but can''t seem to get it to > work. > Basically, I''m trying to toggle the text on a link when it''s clicked > (test.js.rjs): > > page << "if ($(''test_link'').value == ''one'' {" > page.replace_html ''test_link'', ''two'' > page << "} else {" > page.replace_html ''test_link'', ''one'' > page << "}"Syntax error - does not compute. Look closely and see how you forgot the ")" after "''one''". Javascript is very punctuation sensitive, you need to pay special attention to it. Also, use Firefox for testing and install Firebug to debug your javascript. It would have indicated this error. Best regards Peter De Berdt --~--~---------~--~----~------------~-------~--~----~ You received this message because you are subscribed to the Google Groups "Ruby on Rails: Talk" group. To post to this group, send email to rubyonrails-talk-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org To unsubscribe from this group, send email to rubyonrails-talk+unsubscribe-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en -~----------~----~----~----~------~----~------~--~---
> Syntax error - does not compute. > > Look closely and see how you forgot the ")" after "''one''". Javascript > is very punctuation sensitive, you need to pay special attention to > it. Also, use Firefox for testing and install Firebug to debug your > javascript. It would have indicated this error.Thanks Peter. I changed my code to include the closing parenthesis, but it seems to not work still. I am using firefox w/ firebug, although I''m still not that seasoned in debugging js - I''ll read up on that. Here''s what I have now: page << "if ($(''test_link'').value == ''one'') {" page.alert(''hello!'') page << "}" -- Posted via http://www.ruby-forum.com/. --~--~---------~--~----~------------~-------~--~----~ You received this message because you are subscribed to the Google Groups "Ruby on Rails: Talk" group. To post to this group, send email to rubyonrails-talk-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org To unsubscribe from this group, send email to rubyonrails-talk+unsubscribe-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en -~----------~----~----~----~------~----~------~--~---
On 19 Jan 2009, at 10:37, Shilo Ayalon wrote:> Thanks Peter. I changed my code to include the closing parenthesis, > but > it seems to not work still. I am using firefox w/ firebug, although > I''m > still not that seasoned in debugging js - I''ll read up on that. Here''s > what I have now: > > page << "if ($(''test_link'').value == ''one'') {" > page.alert(''hello!'') > page << "}"Then add before your first "page <<" statement: page << "console.log($(''test_link''));" page << "console.log($(''test_link'').value);" There must be something wrong with the value you are trying to access then. Best regards Peter De Berdt --~--~---------~--~----~------------~-------~--~----~ You received this message because you are subscribed to the Google Groups "Ruby on Rails: Talk" group. To post to this group, send email to rubyonrails-talk-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org To unsubscribe from this group, send email to rubyonrails-talk+unsubscribe-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en -~----------~----~----~----~------~----~------~--~---
On 19 Jan 2009, at 09:37, Shilo Ayalon wrote:> > >> Syntax error - does not compute. >> >> Look closely and see how you forgot the ")" after "''one''". Javascript >> is very punctuation sensitive, you need to pay special attention to >> it. Also, use Firefox for testing and install Firebug to debug your >> javascript. It would have indicated this error. > > Thanks Peter. I changed my code to include the closing parenthesis, > but > it seems to not work still. I am using firefox w/ firebug, although > I''m > still not that seasoned in debugging js - I''ll read up on that. Here''s > what I have now:Do links even have a value attribute? It doesn''t seem to contain the links text if that''s what you were expecting. Fred> > > page << "if ($(''test_link'').value == ''one'') {" > page.alert(''hello!'') > page << "}" > > -- > Posted via http://www.ruby-forum.com/. > > >--~--~---------~--~----~------------~-------~--~----~ You received this message because you are subscribed to the Google Groups "Ruby on Rails: Talk" group. To post to this group, send email to rubyonrails-talk-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org To unsubscribe from this group, send email to rubyonrails-talk+unsubscribe-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en -~----------~----~----~----~------~----~------~--~---
> Do links even have a value attribute? It doesn''t seem to contain the > links text if that''s what you were expecting. > > FredFred - I tried using $(''test_link'').innerHtml == ''one'', but the result is the same. Peter - Using firebug, I tried typing in the console the following:>> console.log($(''test_link'').value)undefined>> console.log($(''test_link'').innerHtml)undefined I tried just using a simple span <span id="test">hello</span> to see if console.log works, and I get the same ''undefined'' message, even though it''s showing in the page markup. I don''t want to make this an issue and take up anymore of your time -- I guess I need to improve on my javascript. Thanks for all your help! -- Posted via http://www.ruby-forum.com/. --~--~---------~--~----~------------~-------~--~----~ You received this message because you are subscribed to the Google Groups "Ruby on Rails: Talk" group. To post to this group, send email to rubyonrails-talk-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org To unsubscribe from this group, send email to rubyonrails-talk+unsubscribe-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en -~----------~----~----~----~------~----~------~--~---
On 19 Jan 2009, at 12:10, Shilo Ayalon wrote:> > >> Do links even have a value attribute? It doesn''t seem to contain the >> links text if that''s what you were expecting. >> >> Fred > > Fred - I tried using $(''test_link'').innerHtml == ''one'', but the result > is the same. >That should be: innerHTML Fred> Peter - Using firebug, I tried typing in the console the following: > >>> console.log($(''test_link'').value) > undefined >>> console.log($(''test_link'').innerHtml) > undefined > > I tried just using a simple span <span id="test">hello</span> to see > if > console.log works, and I get the same ''undefined'' message, even though > it''s showing in the page markup. > > I don''t want to make this an issue and take up anymore of your time > -- I > guess I need to improve on my javascript. > > Thanks for all your help! > -- > Posted via http://www.ruby-forum.com/. > > >--~--~---------~--~----~------------~-------~--~----~ You received this message because you are subscribed to the Google Groups "Ruby on Rails: Talk" group. To post to this group, send email to rubyonrails-talk-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org To unsubscribe from this group, send email to rubyonrails-talk+unsubscribe-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en -~----------~----~----~----~------~----~------~--~---