lofaifa Posted December 2, 2011 Share Posted December 2, 2011 if an user doesnt put any word and he click submit , a msg turned on and asks him to re enter cuz the input boxs are empty .. if he re enter just a name another msg (about an empty password box) come and the first msg stays in the page , .. soo i want to clean every error msg after each click on the submit button html : <p id="empty0" style="color:red"></p> <p id="empty1" style="color:red"></p> <p id="empty2" style="color:red"></p> <form name="login" action="proc/login_proc.php" onsubmit="return login_valid1()" method="post"> Username: <input type="text" name="user_name" /><br/> Password: <input type="password" name="user_password" /><br/> <input type="submit" value="Login" /><br/> </form> javascript : function login_valid1() { var x=document.forms["login"]["user_name"].value; var y=document.forms["login"]["user_password"].value; if((x==null || x=="") && (y==null || y=="")) { document.getElementById("empty0").innerHTML="you left the username and the password boxes empty , please try again.<br/>"; return false; } else if(x==null || x=="") { document.getElementById("empty1").innerHTML="you left the username box empty , try again please<br/>"; return false;} else if (y==null ||y==""){ document.getElementById("empty2").innerHTML="you left the password box empty , try again<br/>"; return false; } } Link to comment https://forums.phpfreaks.com/topic/252305-clean-input-boxes/ Share on other sites More sharing options...
sunfighter Posted December 2, 2011 Share Posted December 2, 2011 javascript : function login_valid1() { var x=document.forms["login"]["user_name"].value; var y=document.forms["login"]["user_password"].value; if((x==null || x=="") && (y==null || y=="")) { document.getElementById("empty0").innerHTML="you left the username and the password boxes empty , please try again.<br/>"; return false; } else if(x==null || x=="") { document.getElementById("empty0").innerHTML="you left the username box empty , try again please<br/>"; return false;} else if (y==null ||y==""){ document.getElementById("empty0").innerHTML="you left the password box empty , try again<br/>"; return false; } } OR if the paragraphs are next to the input boxes: javascript : function login_valid1() { var x=document.forms["login"]["user_name"].value; var y=document.forms["login"]["user_password"].value; if((x==null || x=="") && (y==null || y=="")) { document.getElementById("empty0").innerHTML="you left the username and the password boxes empty , please try again.<br/>"; document.getElementById("empty1").innerHTML= ''; document.getElementById("empty2").innerHTML= ''; return false; } else if(x==null || x=="") { document.getElementById("empty1").innerHTML="you left the username box empty , try again please<br/>"; document.getElementById("empty0").innerHTML= ''; document.getElementById("empty2").innerHTML= ''; return false;} else if (y==null ||y==""){ document.getElementById("empty2").innerHTML="you left the password box empty , try again<br/>"; document.getElementById("empty1").innerHTML= ''; document.getElementById("empty0").innerHTML= ''; return false; } } Link to comment https://forums.phpfreaks.com/topic/252305-clean-input-boxes/#findComment-1293613 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.