Login | Register | FAQ
Anonymous

Related to FORM VALIDATION

+ Post a reply

2 posts Page 1 of 1


Related to FORM VALIDATION

by jackkds789 » Sun Sep 27, 2015 6:36 pm

I just to want to check whether the text box is empty or not.If it is empty(null) then i want to display an error message showing "Please Enter the username".
Please have to look on my code and tell me where i m going wrong.
If i dont enter any username then the error message is not visible for e.g In C programming if we dont write getch(); then the output screen does not stay on the screen right. same way its happening here.Message does not stay on the screen. So please help me out.

<html>
<head>
<script>

function checkName(){
var x=document.getElementById('username').value;
if(x=="")
{
document.getElementById('userempty').innerHTML="Please Enter the username";
return false;
}

}

</script>

</head>

<body>
<form method="GET">
<table>
<tr>
<td>Username:</td>
<td><input type="text" id="username"></td>
<td id="userempty"></td>
</tr>
<tr>
<td></td>
<td><input type="Submit" onclick="checkName();" value="Enter"></td>
<td></td>
</tr>

</table>

</form>
</body>
</html>
User avatar

jackkds789

  • Posts: 6
  • Joined: Sun Sep 27, 2015 6:26 pm

Re: Related to FORM VALIDATION

by Farhin Qureshi » Fri Jan 20, 2017 4:38 am

Hi,

I think you have need to try take a input type= "button", because whenever you try to press button that time first print message and than refresh the page, so dont show message.

Code: Select all
<input type="button" onclick="checkName()" value="Enter"/></td>


I hope this is helpful for you.

Thanks,
User avatar

Farhin Qureshi

  • Posts: 41
  • Joined: Tue Jan 03, 2017 11:33 am
--
Farhin Qureshi
.NET Developer
http://www.ifourtechnolab.com


+ Post a reply

Page 1 of 1