# Get javascript value

**URL:** <https://www.ruby-forum.com/t/get-javascript-value/114257>\
**Category:** Rails\
**Created:** [September 10, 2007, 5:41pm UTC](https://www.ruby-forum.com/t/get-javascript-value/114257 "2007-09-10T17:41:10Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![qwerty73](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/q/9d8465/32.png) [@qwerty73](https://www.ruby-forum.com/u/qwerty73)\
**Post date:** [September 10, 2007, 5:41pm UTC](https://www.ruby-forum.com/t/get-javascript-value/114257/1 "2007-09-10T17:41:10Z")

</div>

hi to all,

i’ve this javascript function :

```
function km(str_dir) {
  map = new GMap2(document.getElementById("map_canvas"));
  directionsPanel = document.getElementById("route");
  directions = new GDirections(map, directionsPanel);
  directions.load(str_dir);
  GEvent.addListener(directions,"load", function() {
  var dist= directions.getDistance().meters;
  return dist;
  });
}

```

i call the function from the controller in this way:

@arg=“500 Memorial Drive, Cambridge, MA to Fenway Park, Boston, MA”  
page.call (“km”, @arg)

all work…

the problem is that i want to take the result of javascript function in  
the controller…  
How can i use the variable “dist” inside the controller??

thanks in advance

andre

---

<div class="post-metadata">

**Author:** ![qwerty73](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/q/9d8465/32.png) [@qwerty73](https://www.ruby-forum.com/u/qwerty73)\
**Post date:** [September 10, 2007, 10:20pm UTC](https://www.ruby-forum.com/t/get-javascript-value/114257/2 "2007-09-10T22:20:44Z")

</div>

Andrea C. wrote:

> hi to all,
> 
> i’ve this javascript function :
> 
> ```
> function km(str_dir) {
> map = new GMap2(document.getElementById("map_canvas"));
> directionsPanel = document.getElementById("route");
> 
> ```

You gotta send request to your controller/method using Ajax, that is the  
only way i could think of 🙂

---

<div class="post-metadata">

**Author:** ![qwerty73](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/q/9d8465/32.png) [@qwerty73](https://www.ruby-forum.com/u/qwerty73)\
**Post date:** [September 11, 2007, 9:34am UTC](https://www.ruby-forum.com/t/get-javascript-value/114257/3 "2007-09-11T09:34:19Z")

</div>

Jamal S. wrote:

> Andrea C. wrote:
> 
> > hi to all,
> > 
> > i’ve this javascript function :
> > 
> > ```
> > function km(str_dir) {
> > map = new GMap2(document.getElementById("map_canvas"));
> > directionsPanel = document.getElementById("route");
> > 
> > ```
> 
> You gotta send request to your controller/method using Ajax, that is the  
> only way i could think of 🙂

thanks

i think i have to learn a little bit ajax 🙂
