# RJS Trying to use Javascript variables

**URL:** <https://www.ruby-forum.com/t/rjs-trying-to-use-javascript-variables/132701>\
**Category:** Rails\
**Created:** [March 23, 2008, 7:00pm UTC](https://www.ruby-forum.com/t/rjs-trying-to-use-javascript-variables/132701 "2008-03-23T19:00:55Z")\
**Posts on this page:** 1\
**Page:** 1

<div class="post-metadata">

**Author:** ![deadinplastic](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/d/d2c977/32.png) [@deadinplastic](https://www.ruby-forum.com/u/deadinplastic)\
**Post date:** [March 23, 2008, 7:00pm UTC](https://www.ruby-forum.com/t/rjs-trying-to-use-javascript-variables/132701/1 "2008-03-23T19:00:55Z")

</div>

I’m having problem.  
I have music CD, which can have many tracks.

When adding new CD, there are 5 empty track rows to write in, but there  
is button MORE TRACKS, which adds more tracks where to write.

page.insert\_html :bottom, ‘music\_tracks’, :partial =\> “track\_lines”,  
:locals =\> { :id =\> @tracknr }  
page \<\< “tracknr++”

partial:

 \<%= select\_minute 0, :field\_name =\> 'minute'+id %\>: \<%= select\_second 0, :field\_name =\> 'second'+id %\> \<%= text\_field 'track'+id, 'artist\_name' %\> \<%= text\_field 'track'+id, 'name' %\>

I want to have javascript variable that has track count.  
How can I retrieve javascript variable, I tried:  
x) @tracknr  
x) page \<\< “tracknr”  
and some more, but I can’t figure out…

Maybe there is better solution?

Thanks!
