Pregunta

I have the following 2 following input tags:

<input class="forLoopIndex" type="text" name="n" size="1">
<input class="forLoopIndex" id="typicalElement" type="text" name="k" size="1" placeholder="k">

Since both they have a class called forLoopIndex. I'm trying to store the values when people type on them using keyup. Like this:

    $('.forLoopIndex').keyup(function(){

    forLoopIndex = $(this).val();
    console.log(forLoopIndex);
});

Unfortunately, When I print the value of ForLoopIndex, it only shows the value of the current input where my cursor is. Is there any way to store the values of both my inputs after I have typed? do I need to use an array? any help is more than welcome.

Thanks!

M

¿Fue útil?

Solución

Maybe this can help :

var forloops = $('.forLoopIndex');
var values = [];

forloops.keyup(function(){
    values = [];
    forloops.each(function () {
        values.push($(this).val());
    }
    console.log(values);
});

Whenever the user writes something, the values are updated. You can then save them whenever your want.

Licenciado bajo: CC-BY-SA con atribución
No afiliado a StackOverflow
scroll top