onclick problem

onclick="document.forms['search_form'].search_title.value='<%= u[0]
%>';"

When u[0] = blah'blah (with a single quote), i get the error in firebug:
missing ; before statement
[Break on this error]
document.forms['search_form'].search_tit...f(getElementById('search_id').value=='')

...value='blah'blah'; is causing problems. I guess the ' is ending the
string. How can I workaround this, while still retaining the '?

Thanks

onclick="document.forms['search_form'].search_title.value='<%= u[0]
%>';"

When u[0] = blah'blah (with a single quote), i get the error in firebug:
missing ; before statement
[Break on this error]
document.forms['search_form'].search_tit...f(getElementById('search_id').value=='')

...value='blah'blah'; is causing problems. I guess the ' is ending the
string. How can I workaround this, while still retaining the '?

Convert it to &quot; using one of the rails helpers or CGI htmlescape methods...

It should still appear as a ' in your form.

...value='blah'blah'; is causing problems. I guess the ' is ending the
string. How can I workaround this, while still retaining the '?

Just escape it. I think there's already a function in rails for
escaping strings for javascript.

Fred

escape_javascript(something)

Richard Luther wrote:

escape_javascript(something)

On Aug 8, 1:38 pm, Frederick Cheung <frederick.che...@gmail.com>

Sweet, works great, thanks!