Browse Source

Validation pseudo on enter pressed + Butonn clicked

Baptiste Marty 3 years ago
parent
commit
f3a3320eb7
1 changed files with 7 additions and 5 deletions
  1. 7
    5
      JAVASCRIPT/menu.js

+ 7
- 5
JAVASCRIPT/menu.js View File

@@ -15,10 +15,6 @@ function initError(){
15 15
 }
16 16
 
17 17
 function handleNavigation(event){
18
-    
19
-    if(event.keyCode == 13){
20
-        pseudo = pseudoInput.value;
21
-        console.log(pseudo);
22 18
     if (pseudo){
23 19
         initError();
24 20
         button.childNodes[1].setAttribute("href","etrange_decouverte.html")
@@ -28,6 +24,12 @@ function handleNavigation(event){
28 24
         button.childNodes[1].removeAttribute("href")
29 25
         errorTxt.innerText = "Veuillez rentrer un pseudo svp"
30 26
     }
27
+}
28
+
29
+function handleEnterPressed(event){
30
+    if (event.keyCode == 13){
31
+        pseudo = pseudoInput.value;
32
+        handleNavigation();
31 33
     }
32 34
 }
33 35
 
@@ -41,5 +43,5 @@ initError();
41 43
 
42 44
 // event listeners
43 45
 pseudoInput.addEventListener("change",handlePseudoChange)
44
-pseudoInput.addEventListener("keypress",handleNavigation)
46
+pseudoInput.addEventListener("keypress",handleEnterPressed)
45 47
 button.addEventListener("click",handleNavigation)

Loading…
Cancel
Save