I have a textbox in which the user inserts a text and then I would like, by code, to create a variable with that text. How could I do it?
I have a textbox in which the user inserts a text and then I would like, by code, to create a variable with that text. How could I do it?
You have to use an array to do it:
$variable = [];
$input = $('.texto').text();
$variable[$input] = "negro";
console.log($variable[$input]);
console.log($variable["labrador"]);
console.log($variable.labrador); // que es la opcion que buscaba y que tambien se puede hacer con objetos.
<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script>
<textbox class="texto">labrador</textbox>
Cheshire: indeed what I wanted was the first thing, to create a variable that was named just like what the user had inserted in the texbox.
I have solved it by creating an empty object and then adding a property with the name that was inserted in the texbox.