On enter pressed --> navigate

This commit is contained in:
Baptiste Marty 2020-12-06 10:57:01 +01:00
parent e4fb9b60c2
commit d8566245a1
2 changed files with 16 additions and 10 deletions

View file

@ -130,7 +130,6 @@ main{
background-image: linear-gradient( #5EE283, #057B26);
border-radius: 4vw;
box-shadow: -0.2vw 0.2vw 0.2vw rgba(255, 255, 255, 0.7);
padding:0.8vw 0.8vw 0.5vw 0.8vw;
opacity:0;
animation:fade-text 1s forwards;
animation-delay:6s;
@ -138,6 +137,7 @@ main{
}
#buttonTxt {
padding:0.8vw 0.8vw 0.5vw 0.8vw;
text-decoration:none;
margin:0;
color : black;

View file

@ -14,17 +14,22 @@ function initError(){
errorTxt.innerText = ""
}
function handleNavigation(){
function handleNavigation(event){
if(event.keyCode == 13){
pseudo = pseudoInput.value;
console.log(pseudo);
if (pseudo){
initError();
button.childNodes[1].setAttribute("href","etrange_decouverte.html")
localStorage.setItem("pseudo",pseudo);
button.childNodes[1].click()
} else {
button.childNodes[1].removeAttribute("href")
errorTxt.innerText = "Veuillez rentrer un pseudo svp"
}
}
}
function handlePseudoChange(event){
pseudo = event.target.value;
@ -36,4 +41,5 @@ initError();
// event listeners
pseudoInput.addEventListener("change",handlePseudoChange)
pseudoInput.addEventListener("keypress",handleNavigation)
button.addEventListener("click",handleNavigation)