0

Whats wrong in my code ? The output is to be as if both username and password are empty it should alert no blank else proceed

<!DOCTYPE html> <html> <head> <title>Page Title</title> <script type="text/javascript"> function fn1() { var str1=document.getElementById(text1).value; var str2=document.getElementById(text2).value; if(text1.value ==" "|| text2.value =="") { alert(" no blank"); return false ; } else{ alert(" proceed"); return true; } } </script> </head> <body> <form onsubmit="return fn1()" > <input type= "text" id=" text1" placeholder=" usernamw"><br /> <input type= "password" id=" text2" placeholder=" password"><br /> <button type="submit">submit</button> </form> </body> </html>

23rd Jan 2020, 3:15 PM
SHIVANI
SHIVANI - avatar
6 odpowiedzi
+ 4
Take another look. document.getElementById(here)
23rd Jan 2020, 4:55 PM
Kevin ★
+ 4
Sorry. My mistake. if(str1 ==""||str2 =="")
23rd Jan 2020, 5:09 PM
Kevin ★
+ 3
Compare. function fn1() { var str1=document.getElementById("text1").value; var str2=document.getElementById("text2").value; if(str1.value ==""|| str2.value =="") { alert(" no blank"); return false ; } else{ alert(" proceed"); return true; } } And remove the spaces in Id(input tag)
23rd Jan 2020, 4:09 PM
Kevin ★
+ 1
Thank you sir now I got required output
23rd Jan 2020, 5:14 PM
SHIVANI
SHIVANI - avatar
0
Even though I modify I'm not getting exact output sir please help me <!DOCTYPE html> <html> <head> <title>Page Title</title> <script type="text/javascript"> function fn1() { var str1=document.getElementById(text1).value; var str2=document.getElementById(text2).value; if(str1.value ==""|| str2.value =="") { alert(" no blank"); return false ; } else{ alert(" proceed"); return true; } } </script> </head> <body> <form onsubmit="return fn1()" > <input type= "text" id="text1" placeholder=" usernamw"><br /> <input type= "password" id="text2" placeholder=" password"><br /> <button type="submit">submit</button> </form> </body> </html>
23rd Jan 2020, 4:21 PM
SHIVANI
SHIVANI - avatar
0
Thank you sir, but if condition is not checking this time displaying alert to proceed anything wrong in if condition?? <!DOCTYPE html> <html> <head> <title>Page Title</title> <script type="text/javascript"> function fn1() { var str1=document.getElementById("text1").value; var str2=document.getElementById("text2").value; if(str1.value ==""||str2.value =="") { alert(" no blank"); return false ; } else{ alert(" proceed"); return true; } } </script> </head> <body> <form onsubmit="return fn1()" > <input type= "text" id="text1" placeholder=" username"><br /> <input type= "password" id="text2" placeholder=" password"><br /> <button type="submit">submit</button> </form> </body> </html>
23rd Jan 2020, 5:03 PM
SHIVANI
SHIVANI - avatar