I have a group of labels and I want that when I select 1 or several, the VALUES of each of the labels are displayed in an INPUT TEXT. With this code I can already show ONLY 1 OF THE LABELS, I still can't get the value of more than 2 labels<a>
<input class="tf w-input" id="node" maxlength="256" placeholder="Vida nocturna, el aeropuerto " type="text">
<a class="btn desc fav w-button" id="parque" name="parque" onclick = "add(this);" >PARQUE</a>
<a class="btn desc fav w-button" id="parque" name="parque" onclick = "add(this);">CENTRO COMERCIAL</a>
<a class="btn desc fav w-button" id="parque" name="parque" onclick = "add(this);">GYM</a>
This is the Javascript function with which I get the value only from PARK, the other values I cannot show.
function add(x)
{
var valor = document.getElementById("parque").innerHTML;
document.interes.node.value = valor;
}
I hope you can support me, I appreciate it.
This is the function that prints the value of all the tags on the page.
This will not be the whole answer to your question but I think it can help you.
With this function you will avoid duplicating values in your array. That is, if you click several times on a link, its value will not be repeated in the input text.
using jquery you can do it like this:
if you want to concatenate you can do something like this:
In fact, you would have left over code in your table such as the id, the name and the onclick in your a
the sample code is at: https://jsfiddle.net/madaver1980/494Lg6mq/
if you want you can remove what I tell you so you can see that it works just as correctly, greetings!
don't forget to add jquery src="https://ajax.googleapis.com/ajax/libs/jquery/3.2.1/jquery.min.js
The same way I took the fav class to give the click functionality, if you have more objects with fav class I would be doing the same, so you have to put another name, so you don't have problems.
I would do something like this:
I keep the values of each
<a>
at the moment of giving itclick
in aarray
and tovalue
theinput
one I add thatarray
converted into astring
I hope it helps you, greetings.