0

Can not find the problem. mainly when I giving the code inside "else if". It is not working.

<html> <head> <script> function val(){ var n=document.getElementById("n").value; if(n==""){ document.getElementById("error").innerHTML="enter name"; return false; } if else(n!=""){ document.getElementById("error").innerHTML=""; } } </script> </head> <body> <form name="myf" onSubmit="return val()"> Name:<input type="text" name="Name" id="n"/><br/><p id="error"></p> Address:<input type="text" name="Add" id="a"/><br/><p id="error_1"></p><br/> <input type="submit" value="submit"/> </form> </body> </html>

8th Oct 2018, 9:50 AM
Paramita
Paramita - avatar
6 Respuestas
0
I tried the code and it seems to be working fine... Whenever I leave Name empty, "enter name" shows up. When I do put a name, it disappears. You can try to access the developer console (in Chrome, push F12) and see if you have errors in the Javascript console. https://developers.google.com/web/tools/chrome-devtools/console/
8th Oct 2018, 1:10 PM
fra
fra - avatar
+ 1
thanks a lot...😎
8th Oct 2018, 2:49 PM
Paramita
Paramita - avatar
0
if else(n!="") Should be just an else, since you want it to execute if n!="" As a side note, that is not the correct syntax for an else-if statement: else should precede the if Also, I think you meant to type: n=document.getElementById("n").value; after: var invalid=0;
8th Oct 2018, 10:14 AM
fra
fra - avatar
0
sorry. I posted a wrong code. but now I've changed it
8th Oct 2018, 10:56 AM
Paramita
Paramita - avatar
0
Ok :) you still need, at least, to reverse the if and the else in: if else(n! ="") But you actually only need an else, since you already tested for n == "" in the previous if
8th Oct 2018, 11:30 AM
fra
fra - avatar
0
already I tried it.. actually whenever i not giving any value, it is showing "Enter Name", but after put the value I can not remove it. what I have to do?
8th Oct 2018, 11:37 AM
Paramita
Paramita - avatar