# Dynamic url with javascript? - Help Please

**URL:** <https://www.ruby-forum.com/t/dynamic-url-with-javascript-help-please/53492>\
**Category:** Rails\
**Created:** [February 7, 2006, 5:33pm UTC](https://www.ruby-forum.com/t/dynamic-url-with-javascript-help-please/53492 "2006-02-07T17:33:04Z")\
**Posts on this page:** 5\
**Page:** 1

<div class="post-metadata">

**Author:** ![Matias\_S](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/m/8c91f0/32.png) [@Matias\_S](https://www.ruby-forum.com/u/Matias_S)\
**Post date:** [February 7, 2006, 5:33pm UTC](https://www.ruby-forum.com/t/dynamic-url-with-javascript-help-please/53492/1 "2006-02-07T17:33:04Z")

</div>

Hi,

I’m trying to call a remote function when a combobox option is selected,  
passing as an argument the current value of the combobox (paramenter  
“panel\_id”:

As you can see in this example, the :panel\_id value is hardcoded…  
¿How can I get the value of the combobox dynamically??? I’ve tried by  
replacing the hardcoded value with javascript, but it’s being passed as  
a string to the controller, so the paramenter doesn’t work.

Help Please.

Thanks everybody.

---

<div class="post-metadata">

**Author:** ![Matias\_S](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/m/8c91f0/32.png) [@Matias\_S](https://www.ruby-forum.com/u/Matias_S)\
**Post date:** [February 7, 2006, 5:54pm UTC](https://www.ruby-forum.com/t/dynamic-url-with-javascript-help-please/53492/2 "2006-02-07T17:54:43Z")

</div>

Try using observe\_field()… there are a couple good posts about this.

[http://www.adamhegedus.com/articles/2006/01/19/ajaxed-select-boxes-in-rails](http://www.adamhegedus.com/articles/2006/01/19/ajaxed-select-boxes-in-rails)  
[http://www.roryhansen.ca/?p=9](http://www.roryhansen.ca/?p=9)

---

<div class="post-metadata">

**Author:** ![Matias\_S](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/m/8c91f0/32.png) [@Matias\_S](https://www.ruby-forum.com/u/Matias_S)\
**Post date:** [February 7, 2006, 6:07pm UTC](https://www.ruby-forum.com/t/dynamic-url-with-javascript-help-please/53492/3 "2006-02-07T18:07:09Z")

</div>

Jason C. wrote:

> Try using observe\_field()… there are a couple good posts about this.
> 
> [http://www.adamhegedus.com/articles/2006/01/19/ajaxed-select-boxes-in-rails](http://www.adamhegedus.com/articles/2006/01/19/ajaxed-select-boxes-in-rails)  
> [http://www.roryhansen.ca/?p=9](http://www.roryhansen.ca/?p=9)

Thanks a lot for your help!

That’s what I was looking for.

---

<div class="post-metadata">

**Author:** ![Matias\_S](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/m/8c91f0/32.png) [@Matias\_S](https://www.ruby-forum.com/u/Matias_S)\
**Post date:** [February 7, 2006, 6:13pm UTC](https://www.ruby-forum.com/t/dynamic-url-with-javascript-help-please/53492/4 "2006-02-07T18:13:23Z")

</div>

Matias S. wrote:

> Jason C. wrote:
> 
> > Try using observe\_field()… there are a couple good posts about this.
> > 
> > [http://www.adamhegedus.com/articles/2006/01/19/ajaxed-select-boxes-in-rails](http://www.adamhegedus.com/articles/2006/01/19/ajaxed-select-boxes-in-rails)  
> > [http://www.roryhansen.ca/?p=9](http://www.roryhansen.ca/?p=9)
> 
> Thanks a lot for your help!
> 
> That’s what I was looking for.

Eh, you can do it without observe\_field. I prefer not to since there is  
a slight delay and the extra messiness to deal with. Try this…

\<select id=“server\_interface\_jack\_switch\_panel”  
onchange=“\<%=remote\_function(:update=\>‘server\_interface\_jack\_switch\_id’,:url=\>{:action=\>‘update\_jack\_option’},  
:with =\> “‘panel\_id=’+value”)%\>”\>

---

<div class="post-metadata">

**Author:** ![Matias\_S](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/m/8c91f0/32.png) [@Matias\_S](https://www.ruby-forum.com/u/Matias_S)\
**Post date:** [February 8, 2006, 12:40pm UTC](https://www.ruby-forum.com/t/dynamic-url-with-javascript-help-please/53492/5 "2006-02-08T12:40:49Z")

</div>

Kevin O. wrote:

> Eh, you can do it without observe\_field. I prefer not to since there is  
> a slight delay and the extra messiness to deal with. Try this…
> 
> \<select id=“server\_interface\_jack\_switch\_panel”  
> onchange="\<%=remote\_function(:update=\>‘server\_interface\_jack\_switch\_id’,:url=\>{:action=\>‘update\_jack\_option’},  
> :with =\> “‘panel\_id=’+value”)%\>"\>

mmm… i didn’t realise that the :with parameter could be used with  
remote\_function… cool…

anyway, if you omit the :frequency parameter in observe\_field (that’s  
what I’m doing) the function fires with the “onchange” event, so, no  
delay exists…

Thanks,
