0

Form Validation

hi what is " && n2.value ! "? function validate() { var n1 = document.getElementById("num1"); var n2 = document.getElementById("num2"); if(n1.value != "" && n2.value != "") { if(n1.value == n2.value) { return true; } } alert("The values should be equal and not blank"); return false; }

18th Dec 2018, 5:11 PM
Alireza Babaei
Alireza Babaei - avatar
4 odpowiedzi
+ 4
In addition to Nomeh's answer, take a look at this text about logical operators: https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Operators/Logical_Operators
18th Dec 2018, 7:34 PM
dρlυѕρlυѕ
dρlυѕρlυѕ - avatar
+ 3
You can separe conditions in if () with &&, and the code in execute if all the conditions are true
18th Dec 2018, 5:39 PM
InvBoy [ :: FEDE :: ]
InvBoy [ :: FEDE :: ] - avatar
+ 3
Sorry, my english isn't very good
18th Dec 2018, 5:39 PM
InvBoy [ :: FEDE :: ]
InvBoy [ :: FEDE :: ] - avatar
+ 1
***.value != "" Means that the value of the input element must not be empty which means "" in .js
18th Dec 2018, 5:17 PM
Nomeh Uchenna Gabriel
Nomeh Uchenna Gabriel - avatar