Login | Iscriviti | FAQ
Anonymous

Related to FORM VALIDATION

+ Rispondi al messaggio

2 messaggi Pagina 1 di 1


Related to FORM VALIDATION

da jackkds789 » dom set 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>
Avatar utente

jackkds789

  • Messaggi: 6
  • Iscritto il: dom set 27, 2015 6:26 pm

Re: Related to FORM VALIDATION

da Farhin Qureshi » ven gen 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.

Codice: Seleziona tutto
<input type="button" onclick="checkName()" value="Enter"/></td>


I hope this is helpful for you.

Thanks,
Avatar utente

Farhin Qureshi

  • Messaggi: 45
  • Iscritto il: mar gen 03, 2017 11:33 am
--
Farhin Qureshi
.NET Developer
http://www.ifourtechnolab.com


+ Rispondi al messaggio

Pagina 1 di 1