0
Hello,
I made a screen with a virtual keyboard, for a touch screen application. The client wants two inputs on the same screen and when the user selects an input, the keyboard must enter the values typed in that same input. I have the function working, but the problem is that each time I select an input, multiple instances of the function continue running.
For example: If I tap input 1 3 times and once input 2 and then type "Q" on the keyboard, it is inserted into input 1 "QQQ" and input 2 "Q" all at the same time. How can I stop and restart the function each time an input element is selected?
The function name is termoConsulta(param). I’m using method click() to select the input.
$('#input1').click(function(){
    termoConsulta('#input1');
});
$('#input2').click(function(){
    termoConsulta('#input2');
});
function termoConsulta($escreveInput){
        $('#teclado li').click(function(){
            if(!$(this).is("#consultar")) {
                var $this = $(this),
                    digito = $this.html();
                if($this.hasClass('tecla-x')){
                    var entrada = $escreveInput.val();
                    //apaga último dígito
                    $escreveInput.val(entrada.substr(0,entrada.length-1));
                    return false;
                }
                //escreve o dígito no input
                $escreveInput.val($escreveInput.val()+digito);
            }
        });
        //apaga TUDO
        $('#apagar').click(function(){
            $escreveInput.val('');
        });     
}
						
Enter the code of the thermoConsult function. already tried to associate the event to the function call?
– David Vinicius
@Davidvinicius added the code. How can I associate to the call? Sorry ignorance, I’m learning to program yet.
– Dtag
You mean in the HTML file, with Onclick()?
– Dtag
It’s like this, try using Onclick.
– David Vinicius
I ended up removing the function. Now there is simply a command in the code, and every time an element is clicked, the instructions are called. It works like Onclick. Thank you @Davidvinicius
– Dtag