Race
03-14-2008, 02:55 PM
I'm embarrassed to say that I have not used Javascript in quite a while, but now have to re-familiarize myself with it as I'm learning Ruby and Rails concurrently. :o
Anyway, here's the code I'm working with:
In application.js:
function toggle_visible(obj) {
var el = document.getElementById(obj);
if ( el.style.display != 'none' ) {
el.style.display = 'none';
}
else {
el.style.display = '';
}
}
In the view:
<div id="short_desc_<%= job.id %>">
<%= truncate(job.description, 200) %>
</div>
<div id="long_desc_<%= job.id %>" style="display:none;">
<%= job.description %>
</div>
<%= link_to_function("Expand", "toggle_visible()") %>
This generates an error in Firebug: "el has no properties - toggle_visible(undefined)"
What is it I'm supposed to pass in this situation (since I'm changing the state of two divs)?
Any help is greatly appreciated.
Anyway, here's the code I'm working with:
In application.js:
function toggle_visible(obj) {
var el = document.getElementById(obj);
if ( el.style.display != 'none' ) {
el.style.display = 'none';
}
else {
el.style.display = '';
}
}
In the view:
<div id="short_desc_<%= job.id %>">
<%= truncate(job.description, 200) %>
</div>
<div id="long_desc_<%= job.id %>" style="display:none;">
<%= job.description %>
</div>
<%= link_to_function("Expand", "toggle_visible()") %>
This generates an error in Firebug: "el has no properties - toggle_visible(undefined)"
What is it I'm supposed to pass in this situation (since I'm changing the state of two divs)?
Any help is greatly appreciated.