登录 | 注册 | FAQ
Anonymous

Related to FORM VALIDATION

+ 发表回复

2 篇帖子 分页: 1 / 1


Related to FORM VALIDATION

jackkds789 » 周日 9月 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>
头像

jackkds789

  • 帖子: 6
  • 注册: 周日 9月 27, 2015 6:26 pm

Re: Related to FORM VALIDATION

Farhin Qureshi » 周五 1月 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.

代码: 全选
<input type="button" onclick="checkName()" value="Enter"/></td>


I hope this is helpful for you.

Thanks,
头像

Farhin Qureshi

  • 帖子: 45
  • 注册: 周二 1月 03, 2017 11:33 am
--
Farhin Qureshi
.NET Developer
http://www.ifourtechnolab.com


+ 发表回复

分页: 1 / 1