Load a page after filling a textfield using jQuery

Asked

Viewed 23 times

0

I’m playing a Jokenpo game, and I need a username to put on the Score. In this case I created a home page with a textfield for the user to enter his name. Just after you have entered your name, you should open the other page where the game is with the options.

<div class="container">
    <input type="text" id="nameJogador" placeholder="Nome do Jogador">

</div> 


$(document).ready(function(){

$("#nameJogador").focusout(function(){
    var nomeJogador = $("#nameJogador").val();
    //$("input#nameJogador").load('index_game');
    alert(nomeJogador);
    });


});
  • What exactly are you failing to do?

  • Type I did the event, only I wanted after it loses focus, the variable nameJewer took the value of Txfield, opened the other page where the game is itself and the JS script took this value from that first page to make comparisons.

  • I put an answer, see if that’s what you want.

1 answer

1


If I understand correctly, you can use localStorage to store the name typed in the previous page, e.g.:

<div class="container">
    <input type="text" id="nameJogador" placeholder="Nome do Jogador">
</div> 


$("#nameJogador").focusout(function(){
    var nomeJogador = $(this).val()
    localStorage.setItem('jogador', nomeJogador)

    window.location.href = 'outraPAgina' 
});

Done this you have already gone to the other page and have the player name stored in localStorage, now just recover (when necessary).

$('#score').text('O nome do jogador é: ' + localStorage.jogador)
  • Exactly that brother, thank you very much! It was perfect, thankful for your time!

  • @Vinicius1402 If you have solved, mark as resolvido, by clicking on the icon of check next to the question.

Browser other questions tagged

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