New course! Every coder should learn Generative AI!
Try a free lesson+ 3
Can anyone solve the error of this program
3 Answers
+ 4
In html
<form onsubmit="validate(event)">
...
</form>
In javascript
function validate(evt){
evt.preventDefault();
var n1 = document.getElementById("num1");
var n2 = document.getElementById("num2");
if(n1.value !=""&&n2.value !=""){
if(n1.value==n2.value){
return true;
}
}
alert("Value of both the passwords should match");
return false;
}
+ 4
Replace js code by this.
function validate() {
var n1 = document.getElementById("num1");
var n2 = document.getElementById("num2");
if(n1.value != "" &&n2.value != "") {
if(n1.value == n2.value) {
alert ('Success');
return true;
}
alert("Value of both the passwords should match");
}
return false;
}
+ 2
Use this
<input type="button" onclick="return validate()" value="Submit">