samedi 22 avril 2017

Javascript if/else on submit

im totally new to javascript and im currently working on my first functions. I have these 2 text input area where one can put his name and his level.

<form action="/action_page.php">
Nom: <input type="text" name="fullname"><br><br>
Niveau (1 &aacute; 6): <input type="text" name="niveau">
<input type="submit" value="Afficher partie 2">
</form> 

After submitting, the user is supposed to be shown a message with his name and his level (if level is between 1-6, else its an error message).

This is how i wrote my script:

 var x = oninput;
    var y = oninput;
    if (y>=1){
    document.write("Bonjour + 'x'");
    document.write("Niveau='y'");
    }if (y<=6){
    document.write("Bonjour + 'x'");
    document.write("Niveau='y'");
    }
   else {
    document.write("<p style="color:red;">Erreur le niveau doit etre en  
    1 et 6</p>
    }
    </script>

I really wanted to know if I wrote that the right way, I also cant figure how to show the user his name with the variable X.

I also have a problem understanding how to link my script to the input box.

Aucun commentaire:

Enregistrer un commentaire