The problem is that I can't get value of my password fields - alert with pso1 returns null.
I don't see any error in this code so I'm asking for help.
<form class='container' onsubmit="return checkit()">
<h1> Javascript </h1>
Login <input type='text' id='log'><br>
Password <input type='password' id='pso1'><br>
Confirm passwordd <input type='password' id='pso2'><br>
<button>Register</button>
</form>
<script type="text/javascript">
var pso1=document.getElementById('pso1').value ;
var pso2=document.getElementById('pso2').value ;
alert(pso1);
function checkit(){
if(pso1=!pso2){
return false;
alert('Passwords are not the same.');
}
else{
return true;
alert('work');
}
}
</script>
</body>
In your code you are setting the values of pso1
and ps02
once right after the page load before their values are changed. You will want to update these values instead, declared them as local variables inside your function:
function checkit(){
var pso1=document.getElementById('pso1').value;
var pso2=document.getElementById('pso2').value;
if(pso1=!pso2){
return false;
alert('Passwords are not the same.');
}
else{
return true; alert('work');
}
}