# Using instance variable within JavaScript function loaded in a partial

**URL:** <https://www.ruby-forum.com/t/using-instance-variable-within-javascript-function-loaded-in-a-partial/162698>\
**Category:** Rails\
**Created:** [March 12, 2009, 10:00pm UTC](https://www.ruby-forum.com/t/using-instance-variable-within-javascript-function-loaded-in-a-partial/162698 "2009-03-12T22:00:53Z")\
**Posts on this page:** 2\
**Page:** 1

<div class="post-metadata">

**Author:** ![david](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/d/aeb1de/32.png) [@david](https://www.ruby-forum.com/u/david)\
**Post date:** [March 12, 2009, 10:00pm UTC](https://www.ruby-forum.com/t/using-instance-variable-within-javascript-function-loaded-in-a-partial/162698/1 "2009-03-12T22:00:53Z")

</div>

Im wondering, how do I go about allowing my javascript function to  
load the updated instance variable that is loaded within a partial?  
To be specific, I have a javascript function call:  
onmousedown=“changeTab(this)” for a tab in my layout. This function  
passes an instance variable with an Ajax.Request like so:

changeTab(tab) {  
new Ajax.Request( ‘/test/ajax’, {parameters: { date: \<%=  
array\_or\_string\_for\_javascript(@date) %\> })  
}

@date is changed each time a different link\_to\_remote is called and  
the link\_to\_remote catches this change and send the updated @date  
variable, but my javascript function changeTab does not pass the  
updated @date variable. How do I get the changeTab javascript  
function to pass the new updated @date variable?

---

<div class="post-metadata">

**Author:** ![david](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/d/aeb1de/32.png) [@david](https://www.ruby-forum.com/u/david)\
**Post date:** [March 12, 2009, 11:27pm UTC](https://www.ruby-forum.com/t/using-instance-variable-within-javascript-function-loaded-in-a-partial/162698/2 "2009-03-12T23:27:43Z")

</div>

On Mar 12, 9:00 pm, David [removed\_email\_address@domain.invalid](mailto:removed_email_address@domain.invalid) wrote:

> }  
> This code is only evaluated once so what happens is normal. One way of  
> doing things is to have the date be a parameter of changeTab (assuming  
> that whatever calls changeTab is updated after these requests).  
> Another is to have your requests update some global javascript  
> variable

Fred
