\n \n \n
\n
\n \n
\n \n \n
\n \n","answerCount":6,"upvoteCount":0,"suggestedAnswer":[{"@type":"Answer","text":"Take another look.\n document.getElementById(here)","upvoteCount":4},{"@type":"Answer","text":"Sorry. My mistake.\nif(str1 ==\"\"||str2 ==\"\")","upvoteCount":4},{"@type":"Answer","text":"Compare.\n function fn1()\n {\n var str1=document.getElementById(\"text1\").value;\n var str2=document.getElementById(\"text2\").value;\n if(str1.value ==\"\"|| str2.value ==\"\")\n {\n alert(\" no blank\");\n return false ; \n }\n else{\n alert(\" proceed\");\n return true;\n }\n }\n\nAnd remove the spaces in Id(input tag)","upvoteCount":3},{"@type":"Answer","text":"Thank you sir now I got required output","upvoteCount":1},{"@type":"Answer","text":"Even though I modify I'm not getting exact output sir please help me \n\n\n\n \n Page Title\n \n \n \n
\n
\n \n
\n \n \n
\n \n","upvoteCount":0},{"@type":"Answer","text":"Thank you sir, but if condition is not checking this time displaying alert to proceed anything wrong in if condition?? \n\n\n \n Page Title\n \n \n \n
\n
\n \n
\n \n \n
\n \n","upvoteCount":0}]} }
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 ответов
+ 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