# Update\_field question

**URL:** <https://www.ruby-forum.com/t/update-field-question/51149>\
**Category:** Rails\
**Created:** [December 27, 2005, 8:32am UTC](https://www.ruby-forum.com/t/update-field-question/51149 "2005-12-27T08:32:09Z")\
**Posts on this page:** 1\
**Page:** 1

<div class="post-metadata">

**Author:** ![sean](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/s/f0a364/32.png) [@sean](https://www.ruby-forum.com/u/sean)\
**Post date:** [December 27, 2005, 8:32am UTC](https://www.ruby-forum.com/t/update-field-question/51149/1 "2005-12-27T08:32:09Z")

</div>

I’m using update\_field to update a

 with the contents of a  
text\_area as it’s updated by the user (a-la-Typo preview style).

I’m now trying to preload the

 so that it shows the contents of the  
field being edited even if that field doesn’t get edited. In other  
words, update\_field is only called if the field is updated, but I want  
the same 
 to show the contents of the field even if the user  
doesn’t edit the field (the reason being that the 
 is the  
textilized contents of the field).

So my idea was to have another

 with the field contents, and then  
remove or clear that 
 when the update\_field is called (so it isn’t  
displayed twice).

so in my rhtml file I have:

# this div is preloaded with field contents

```
<div id="pre_preview" class="post"><%= textilize(@song_words_chords) 

```

%\>

# this div is updated by update\_field

```
<div id="preview" class="post"></div>

```

\<%= observe\_field “song\_words\_chords”,  
:frequency =\> 1,  
:update =\> “preview”,  
:url =\> { :action =\> “preview” },  
:with =\> “‘song\_words\_chords=’ + escape(value)” %\>

then in my preview.rhtml, which is called by the preview action (which  
updates the contents of @song\_words\_chords, I have:

\<%= update\_element\_function("pre\_preview", { :action =\> :empty }) %\>

\<%= textilize(@song\_words\_chords) %\>

But instead of emptying the “pre\_preview” div, update\_element\_function  
just displays the following on the page:

$(‘pre\_preview’).innerHTML = ‘’;

Does update\_element\_function only work on div’s defined in the same  
rhtml file? Or am I misusing it?

I have a feeling I’m using an altogether incorrect approach for this  
anyway, but being new to both Rails and JS I’m not sure what the correct  
approach would be.

Any advice would be appreciated. Thanks!
