rjs not updating my page

hi,

I have this:

page.hide "transactionpopup" page.replace_html @shift.shifttype.name+"_"+@shift.date.strftime('%d-%m-%Y') ,calendarday(:shift=>@shift) @exchangeproposals.each do |ep|   domid=ep.shift.shifttype.name+"_"+ep.shift.date.strftime('%d-%m-%Y')   page << "if $('#{domid}') {"     page.replace_html domid ,calendarday(:shift=>ep.shift)   page << "}" end

the problem is with this part:

page << "if $('#{domid}') {" page << "}"

when i use this, my script doesn't work. , nothing happens and I am not getting errors at all

I dont have a clue what the problem is. when i check with firebug i see this response:

try {

Element.hide("transactionpopup");

Element.update("Nacht_30-05-2008", "\u003Cdiv style='width:90%'\u003Ejos\u003Cbr\u003E\u003Cimg alt=

\"Negotiate\" border=\"0\" src=\"/images/negotiate.gif?1210763277\" /\u003E\u003C/div\u003E");

if $('Nacht_29-05-2008') {

Element.update("Vroeg_21-05-2008", "\u003Cdiv style='width:100%; height:100%;background:#d0e6f6'\u003Eremco

\u003C/div\u003E");

}

} catch (e) { alert('RJS error:\n\n' + e.toString()); alert('Element.hide(\"transactionpopup\");\nElement

.update(\"Nacht_30-05-2008\", \"\\u003Cdiv style=\'width:90%\'\\u003Ejos\\u003Cbr\\u003E\\u003Cimg alt

=\\\"Negotiate\\\" border=\\\"0\\\" src=\\\"/images/negotiate.gif?1210763277\\\" /\\u003E\\u003C/div

\\u003E\");\nif $(\'Nacht_29-05-2008\') {\nElement.update(\"Vroeg_21-05-2008\", \"\\u003Cdiv style=\'width

:100%; height:100%;background:#d0e6f6\'\\u003Eremco\\u003C/div\\u003E\");\n}'); throw e }

the problem is with this part:

page << "if $('#{domid}') {" page << "}"

when i use this, my script doesn't work. , nothing happens and I am not getting errors at all

I dont have a clue what the problem is. when i check with firebug i see this response:

That's invalid syntax. It should be if( ...) {

Fred

As an alternative to building fractured JS, check into using page.select, which allows you to use css-style selectors to locate dom elements. select can also be chained with methods like .any, .all, etc so that you can iterate over the elements that you find. In this case select(...).any(elem){elem.replace_html 'blah'} would allow you to replace the element if it exists. The advantage will be that the intention of the code will be much clearer when you read it later.

AndyV

Frederick Cheung wrote:

That's invalid syntax. It should be if( ...) {

Fred

oops, thanks fred, i guess i overlooked it

whow, this is a very cool feature i didn't know about, thanks for showing me :slight_smile:

AndyV wrote: