Capture a state name (uf) and an image

1

Good night everyone.

I have an image of Brazil with its states:

HowdoI,ifIclickontheimageofthestateofSãoPaulo,fillinthisnameinatextfield.

<inputtype="text" name="uf" id="uf"  value="">

Thank you in advance for your help.

    
asked by anonymous 17.10.2016 / 22:28

1 answer

3

In order to know where to click the best is to have an SVG that has elements for each region and JavaScript can know where the click occurred.

To caprat this you can do so, for example:

The structure of SVG ( SVG example copied from here ):

 <g>
    <a xlink:href="#tocantins">
    ... etc

and jQuery

$('svg a').on('click', function(e) {
    e.preventDefault();
    var id = this.getAttributeNS('http://www.w3.org/1999/xlink', 'href').slice(1);
    $('input').val(id);
});

Example online: link

    
17.10.2016 / 22:35