0
Can anyone help me here i am trying to validate information on 2 textboxs using JavaScript and i dnt know where am making mistak
<html> <body> <form method="post" onsubmit="return valid()"> name:<input type ="text" id="name1"> </br> Surname:<input type ="text" id="name2"> </br> <input type="submit" value="submit button"> </form> <script> function valid(){ var n1 = document.getElementById("name1"); var n2 = document .getElementById("name2"); if (n1.value !=){ if (n2.value !=){ alert("thank you for taking your time") return true } } alert("The values should be equal and not blank") return false } </script>
5 ответов
- 1
Remove the ; before the { on your if statements
+ 1
thanks
+ 1
thanks its working now I did it like did
if n1.value ="" && n2.value=""{
}
0
my coding now is like this am having a problem if value its not null I got alert saying thanks for taking ur time also wen it is null am still getting the same alert saying thanks for taking ur time
<html>
<body>
<form method="post" onsubmit="return valid()">
name:<input type ="text" id="name1">
</br>
Surname:<input type ="text" id="name2">
</br>
<input type="submit" value="submit button">
</form>
<script>
function valid(){
var n1 = document.getElementById("name1");
var n2 = document .getElementById("name2");
if (n1.value !=" ");{
if (n2.value !=" ");{
alert("thanks you for taking your time") ;
return true;
}
}
alert("The values should be equal and not blank") ;
return false;
}
</script>
</body>
</html>
- 2
You need something after != to compare with, "" should work. You need ; on a bunch of your statements.