Topic: How do I pass a variable to this js???

So here is my code that I have so far. It doesn't work... :

  function gmap_update_position(model){
    lat = document.getElementById($(model)+"lat");
    lon = document.getElementById($(model)+"lon");
    lat.value = ""+ marker.getPoint().lat();
    lon.value = ""+ marker.getPoint().lng();

I want to pass the 'model'  variable to the 'getElementById'. It should read:  getElementById("model_lat");

However replacing the model with whatever the variable is.

I am useless at Js, any help would be greatly appreciated!

Re: How do I pass a variable to this js???

consider $() as getElementById;
$() return an Element object. You're trying to add string to an Element object. Does it have sense?

If your var "model" is a string that represent some html id, just do this:

function gmap_update_position(model) {
  var lat = $(model + "lat");
  var lon = $(model + "lon");

  // ....