Display certain image for milled numbers

-1

I have the following <input> and <img> on the page.

<input class="form-control" id="cordenadasaqui" value="47644.63956 74592.843" readonly>

<img id="imagemaqui" src="http://www.meusite.com/los-santos.jpg">
  

Ineedtomakeadifferentimageappearforeachsetofcoordinatesdisplayed.

Example

Ifthe<input>aboveiswiththevalue=" " contained in the first 11 characters:
47644.63956

The displayed image will be:

<img id="imagemaqui" src="http://www.meusite.com/los-santos.jpg">

Ifyouhavevalue=" " containing the following numbers in the first 11 characters:
87635.98456

The displayed image will be:

<img id="imagemaqui" src="http://www.meusite.com/las-venturas.jpg">

Tosimplifythequestion

  

In%w/w%acertainsetofnumberswillbeloaded,andthenonlythefirst11characters(10numbersand1point".") should be fetched.

If these first 11 characters are value=" " = 47644.63956

If these first 11 characters are los-santos.jpg = 87635.98456

And so on ... How to do this?

    
asked by anonymous 19.12.2016 / 03:37

1 answer

2

I believe this code will solve your problem. When loading the page it takes the value of the input and compares it according to what you said. And doing the assignment in the image:

<input class="form-control" id="cordenadasaqui" value="87635.98456 74592.843" readonly>

<img id="imagemaqui" src="http://www.meusite.com/los-santos.jpg"><script>$(document).ready(function(){varcoordenadas=$("#cordenadasaqui").val().substr(0,11);
   var img="";
if(coordenadas=="47644.63956"){
img="http://www.meusite.com/los-santos.jpg";
    }
else if(coordenadas=="87635.98456"){
        img="http://www.meusite.com/las-venturas.jpg";
    }
    $("#imagemaqui").attr("src",img);
});
</script>

I used Jquery. I hope I have helped !!

    
19.12.2016 / 03:59