Friday, September 24, 2010
Rails - RJS ERROR: TypeError element is null
Usually this error is caused by "page.replace_html 'div_1', render()". Do you have "div_1" defined anywhere in the html?
Wednesday, March 31, 2010
Javascript in Rails Partial
Javascript function defined in a partial sometimes doesn't work (I've seen both worked case and non-worked case). I have a partial named _v_1_0_edit.html.erb; its parent page is index.html.erb. The javascript portion is below:
If the above is inside a partial, it doesn't work when I call my_alert() from a onclick event of a button on the partial; it is as if the function is not defined. But if the above is inside the parent, it works.
However, if I change the function definition to below:
It works if it's defined in a partial (But it doesn't work in IE).
If I just throw the below on a view:
It will show the alert message no matter it's on the partial or the parent.
I need to do more research on this. I think as long as the defined function is shown on page source, it should work. Can I have a script
section inside a div?
function my_alert() {
alert("Hello");
}
If the above is inside a partial, it doesn't work when I call my_alert() from a onclick event of a button on the partial; it is as if the function is not defined. But if the above is inside the parent, it works.
However, if I change the function definition to below:
my_alert = function my_alert() {
alert("Hello");
}
It works if it's defined in a partial (But it doesn't work in IE).
If I just throw the below on a view:
alert("Hello");
It will show the alert message no matter it's on the partial or the parent.
I need to do more research on this. I think as long as the defined function is shown on page source, it should work. Can I have a script
section inside a div?
Subscribe to:
Posts (Atom)