samedi 24 février 2018

javascript alert is not working correctly with if statements

I would like to check if the mark I selected and input value are the same or not, but the alert in js works even though when they are same.Here is my code! Thanks for your support!

<select id="mark">
    <option value="o">o</option>
    <option value="x">x</option> 
</select>
<input type="text" name="block%s" id="block" onchange="check()">

var mark=document.getElementById("mark").value;
var block=document.getElementById("block").value;
function check(){
if( block != mark) { 
    alert ('Your mark is wrong'); 
    return false; 
}
else{
    return true; 
}
}  

Aucun commentaire:

Enregistrer un commentaire