mixing onlick functions in link_to_function

  • Thread starter Mike Dershowitz
  • Start date
M

Mike Dershowitz

Hi:

This is giving an error:

<%= link_to_function "expand",
"Element.toggle('in#{msg.id}');
Element.show('col#{msg.id}'); Element.hide('ex#{msg.id}');
document.getElementById('#{msg.id}').style.backgroundColor = 'white';
{new Ajax.Request('/messages/msg_read/#{msg.id}, {asynchronous:true,
evalScripts:true})}" %>

I've tried it a bunch of different ways but I still get an:

"unterminated string literal"

error.

Any help you can provide would be greatly appreciated - or Is there a
better way?

Thanks!

Mike
 
A

Alex Young

Mike said:
Hi:

This is giving an error:

<%= link_to_function "expand",
"Element.toggle('in#{msg.id}');
Element.show('col#{msg.id}'); Element.hide('ex#{msg.id}');
document.getElementById('#{msg.id}').style.backgroundColor = 'white';
{new Ajax.Request('/messages/msg_read/#{msg.id}, {asynchronous:true,
--------------------^

This quote mark isn't closed.
 
R

Rob Biedenharn

Hi:

This is giving an error:

<%= link_to_function "expand",
"Element.toggle('in#{msg.id}');
Element.show('col#{msg.id}'); Element.hide('ex#{msg.id}');
document.getElementById('#{msg.id}').style.backgroundColor = 'white';
{new Ajax.Request('/messages/msg_read/#{msg.id}, {asynchronous:true,
evalScripts:true})}" %>

I've tried it a bunch of different ways but I still get an:

"unterminated string literal"

error.

Any help you can provide would be greatly appreciated - or Is there a
better way?

Thanks!

Mike

<%= link_to_function "expand" do |page|
page.toggle "in#{msg.id}"
page.show "col#{msg.id}"
page.hide "ex#{msg.id}"
page << "$('#{msg.id}').style.backgroundColor = 'white';"
remote_function:)url => '/messages/msg_read/#
{msg.id}') #<<== messages_msg_read_path(msg) perhaps?
end %>

gives:

<a href="#" onclick="try {
Element.toggle(&quot;in18&quot;);
Element.show(&quot;col18&quot;);
Element.hide(&quot;ex18&quot;);
$('18').style.backgroundColor = 'white';
} catch (e) { alert('RJS error:\n\n' + e.toString()); alert
('Element.toggle(\&quot;in18\&quot;);\nElement.show(\&quot;col18
\&quot;);\nElement.hide(\&quot;ex18\&quot;);\n$(\'18
\').style.backgroundColor = \'white\';'); throw e }; return
false;">expand</a>

Which is clearly easier to read (and find that missing ' that Alex
pointed out), right?

-Rob

Rob Biedenharn http://agileconsultingllc.com
(e-mail address removed)
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
473,731
Messages
2,569,432
Members
44,832
Latest member
GlennSmall

Latest Threads

Top