# Rjs not updating my page

**URL:** <https://www.ruby-forum.com/t/rjs-not-updating-my-page/138277>\
**Category:** Rails\
**Created:** [May 21, 2008, 4:32pm UTC](https://www.ruby-forum.com/t/rjs-not-updating-my-page/138277 "2008-05-21T16:32:45Z")\
**Posts on this page:** 5\
**Page:** 1

<div class="post-metadata">

**Author:** ![remcoh](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/r/c37758/32.png) [@remcoh](https://www.ruby-forum.com/u/remcoh)\
**Post date:** [May 21, 2008, 4:32pm UTC](https://www.ruby-forum.com/t/rjs-not-updating-my-page/138277/1 "2008-05-21T16:32:45Z")

</div>

hi,

I have this:

page.hide “transactionpopup”  
page.replace\_html  
@shift.shifttype.name+"_“removed\_email\_address@domain.invalid(’%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 }

---

<div class="post-metadata">

**Author:** ![remcoh](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/r/c37758/32.png) [@remcoh](https://www.ruby-forum.com/u/remcoh)\
**Post date:** [May 21, 2008, 4:52pm UTC](https://www.ruby-forum.com/t/rjs-not-updating-my-page/138277/2 "2008-05-21T16:52:30Z")

</div>

> 

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

Fred

---

<div class="post-metadata">

**Author:** ![remcoh](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/r/c37758/32.png) [@remcoh](https://www.ruby-forum.com/u/remcoh)\
**Post date:** [May 21, 2008, 9:05pm UTC](https://www.ruby-forum.com/t/rjs-not-updating-my-page/138277/3 "2008-05-21T21:05:02Z")

</div>

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

On May 21, 10:50 am, Frederick C. [removed\_email\_address@domain.invalid](mailto:removed_email_address@domain.invalid)

---

<div class="post-metadata">

**Author:** ![remcoh](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/r/c37758/32.png) [@remcoh](https://www.ruby-forum.com/u/remcoh)\
**Post date:** [May 22, 2008, 9:52am UTC](https://www.ruby-forum.com/t/rjs-not-updating-my-page/138277/4 "2008-05-22T09:52:32Z")

</div>

whow, this is a very cool feature i didn’t know about, thanks for  
showing me 🙂

AndyV wrote:

> 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
> 
> On May 21, 10:50 am, Frederick C. [removed\_email\_address@domain.invalid](mailto:removed_email_address@domain.invalid)

---

<div class="post-metadata">

**Author:** ![remcoh](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/r/c37758/32.png) [@remcoh](https://www.ruby-forum.com/u/remcoh)\
**Post date:** [May 22, 2008, 9:39am UTC](https://www.ruby-forum.com/t/rjs-not-updating-my-page/138277/5 "2008-05-22T09:39:43Z")

</div>

Frederick C. wrote:

> > 
> 
> That’s invalid syntax. It should be if( …) {
> 
> Fred

oops, thanks fred, i guess i overlooked it
