Map image and save array to database

Asked

Viewed 140 times

0

I have an image of the human dental arch. I want to display it and when clicked on a given tooth, the value was filling in an input text field.

Example:

[13,12,11]

The image I’m going to use is this:

inserir a descrição da imagem aqui

The idea is to click on tooth 11, 12 and 13 your values be filled in the form field to be inserted in the bank.

I believe this is with javascript, but I’m lost in it. Could you help me?

  • Welcome to sopt. What have you tried to do? It would be interesting to post a [mcve]. So it is easier to guide you.

  • That image will always be the same or you’ll get different images for each patient?

  • @Diegof have no idea how to start.

  • @Sergio will be the same image yes.

  • I suggest you use something more practical. A SVG would be better. Something like this: https://jsfiddle.net/jkwj423z/ (with a lot of work it might be good).

  • @Sergio the idea is to click on a given tooth, example: 10 and another tooth, 31 ... when clicking on these two teeth, the values 10 and 31 were for an input text field of my form.

  • Well, I’ve managed to map the image using the tags below: <img src="_Imagens/arcada.png" width="500" border="0" usemap="#Map" class="bordaimg" />&#xA; &#xA; <map name="Map" id="Map">&#xA; &#xA; <area shape="rect" coords="217,8,247,101" href="javascript:AQUI_O_JS('11','dentes_id');" title="Dente 11" /></map>

  • Now I’m breaking my head to make a JS that takes the value "11" and plays in the field inpu text with the ID "dentes_id".

Show 3 more comments

1 answer

1

On wikipedia there is an SVG which may be adapted to have numbers. I made this adaptation and with a loop you can join event headphones and an input that does what you want. Javascript could be like this:

var paths = [].slice.call(document.querySelectorAll('path.selectable'));
var text = [].slice.call(document.querySelectorAll('text'));
var input = document.querySelector('input');
var selecionados = [];

for (var i = 0; i < paths.length; i++) {
    paths[i].addEventListener('click', handler(text[i].innerHTML));
}

function handler(nr) {
    return function() {
        var selected = this.classList.toggle('selected');
        if (selected) selecionados.push(nr);
        else selecionados = selecionados.filter(function(_nr){ return _nr != nr; });
        input.value = selecionados.join(', ');
    }
}

What this does is select/de-select teeth, and join the selected tooth number in the input.

jsFiddle: https://jsfiddle.net/4o0q7sc8/

Browser other questions tagged

You are not signed in. Login or sign up in order to post.