# Pass variables inside the page

**URL:** <https://www.ruby-forum.com/t/pass-variables-inside-the-page/160165>\
**Category:** Rails\
**Created:** [February 12, 2009, 1:40pm UTC](https://www.ruby-forum.com/t/pass-variables-inside-the-page/160165 "2009-02-12T13:40:14Z")\
**Posts on this page:** 8\
**Page:** 1

<div class="post-metadata">

**Author:** ![enzor](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/e/bbe5ce/32.png) [@enzor](https://www.ruby-forum.com/u/enzor)\
**Post date:** [February 12, 2009, 1:40pm UTC](https://www.ruby-forum.com/t/pass-variables-inside-the-page/160165/1 "2009-02-12T13:40:14Z")

</div>

Hi!

I need to create a combobox which , depending on the selected value,  
will display different items whithout reloading the page

\<%= select(“product”,“choice”, Pricebooks.find(:all).collect { |p|  
[p.name,p.id]}, {:selected =\> Pricebooks.find(:first)} , {onchange =\>  
???)%\>

How can i retrieve the value of the selected product through onchange?

thanx in advance

enzo rivello

---

<div class="post-metadata">

**Author:** ![enzor](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/e/bbe5ce/32.png) [@enzor](https://www.ruby-forum.com/u/enzor)\
**Post date:** [February 12, 2009, 2:16pm UTC](https://www.ruby-forum.com/t/pass-variables-inside-the-page/160165/2 "2009-02-12T14:16:51Z")

</div>

On 12 Feb 2009, at 12:40, Enzo R. wrote:

> How can i retrieve the value of the selected product through onchange?

is this entirely client side or do you want to make an ajax request ?

Fred

---

<div class="post-metadata">

**Author:** ![enzor](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/e/bbe5ce/32.png) [@enzor](https://www.ruby-forum.com/u/enzor)\
**Post date:** [February 12, 2009, 2:17pm UTC](https://www.ruby-forum.com/t/pass-variables-inside-the-page/160165/3 "2009-02-12T14:17:16Z")

</div>

Frederick C. wrote:

> On 12 Feb 2009, at 12:40, Enzo R. wrote:
> 
> > How can i retrieve the value of the selected product through onchange?
> 
> is this entirely client side or do you want to make an ajax request ?
> 
> Fred

if possible only on client side

---

<div class="post-metadata">

**Author:** ![enzor](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/e/bbe5ce/32.png) [@enzor](https://www.ruby-forum.com/u/enzor)\
**Post date:** [February 12, 2009, 2:19pm UTC](https://www.ruby-forum.com/t/pass-variables-inside-the-page/160165/4 "2009-02-12T14:19:13Z")

</div>

That’s pure JS then.

onChange(this), and treat it accordingly…

On Thu, Feb 12, 2009 at 11:17 AM, Enzo R. \<

---

<div class="post-metadata">

**Author:** ![enzor](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/e/bbe5ce/32.png) [@enzor](https://www.ruby-forum.com/u/enzor)\
**Post date:** [February 12, 2009, 2:27pm UTC](https://www.ruby-forum.com/t/pass-variables-inside-the-page/160165/5 "2009-02-12T14:27:35Z")

</div>

Mathieu R. wrote:

> That’s pure JS then.
> 
> onChange(this), and treat it accordingly…
> 
> On Thu, Feb 12, 2009 at 11:17 AM, Enzo R. \<

and trough server side, how would it be?

---

<div class="post-metadata">

**Author:** ![enzor](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/e/bbe5ce/32.png) [@enzor](https://www.ruby-forum.com/u/enzor)\
**Post date:** [February 12, 2009, 2:20pm UTC](https://www.ruby-forum.com/t/pass-variables-inside-the-page/160165/6 "2009-02-12T14:20:24Z")

</div>

oops.  
onChange(yourFunction(this));

On Thu, Feb 12, 2009 at 11:18 AM, Mathieu R. \<

---

<div class="post-metadata">

**Author:** ![enzor](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/e/bbe5ce/32.png) [@enzor](https://www.ruby-forum.com/u/enzor)\
**Post date:** [February 12, 2009, 5:56pm UTC](https://www.ruby-forum.com/t/pass-variables-inside-the-page/160165/7 "2009-02-12T17:56:26Z")

</div>

Mathieu R. wrote:

> well, you can submit a classic form request and reload the whole page,  
> or  
> submit an ajax request and then update just a part of your page. I think  
> that you should decide what you want do, then hack this solution. Not  
> decide  
> what you want to do because it seems simpler to do.
> 
> On Thu, Feb 12, 2009 at 11:27 AM, Enzo R. \<

thanx a lot i resolved the problem with a classic form!  
thank you!

---

<div class="post-metadata">

**Author:** ![enzor](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/e/bbe5ce/32.png) [@enzor](https://www.ruby-forum.com/u/enzor)\
**Post date:** [February 12, 2009, 2:32pm UTC](https://www.ruby-forum.com/t/pass-variables-inside-the-page/160165/8 "2009-02-12T14:32:44Z")

</div>

well, you can submit a classic form request and reload the whole page,  
or  
submit an ajax request and then update just a part of your page. I think  
that you should decide what you want do, then hack this solution. Not  
decide  
what you want to do because it seems simpler to do.

On Thu, Feb 12, 2009 at 11:27 AM, Enzo R. \<
