# Other Languages > jQuery >  [RESOLVED] Validation for blank input field

## systech44

Hello,

I am trying to put a simple validation for the input text field. In the browser this is working something like this.
1st click - no message is displaying.
2nd click - message is displaying 2 times.
3rd click - message is displaying 3 times.
and so on.

Here is the code.


```
<html>
<head>
<title>jQuery Input Blank</title>
<script type="text/javascript" src="js/jquery-1.10.1.js"></script>
<script type="text/javascript">
function validate()
{
	$(document).ready(function(){
		$("#button").click(function(){
			if($.trim($("#name").val()) == ""){
				alert("Name cannot be blank");
				return false;
			}
		});
	});
}
</script>
</head>
<body>
Name:<input type="text" id="name" name="name" />
<input type="button" id="button" name="button" value="Submit" onclick="validate()" />
</body>
</html>
```

Please help me to resolve the issue.

Regards & Thanks.

----------


## tr333

Most browsers now will support the new HTML5 form validation attributes.  When combined with the correct input type (text, number, tel, email, date, time, etc.) and some polyfills, it's incredibly easy to do forms with proper validation (ignoring the fact that you should also be doing server-side validation).  Why code it yourself when you can get the browser to do the heavy lifting for you?


html Code:
<input type="text" id="name" name="name" required />

If the built-in stuff doesn't suffice, there is always a good plugin for jQuery floating around to help you out.

----------


## systech44

tr333 - thanks a lot for the reply. But what if I wish to give the validation using jquery! Please help, if possible. I am looking for response and will resolved the thread.

----------


## systech44

Here is the solution I was looking for. Now it is resolved.



```
<html>
<head>
<title>jQuery Input Blank</title>
<script type="text/javascript" src="js/jquery-1.10.1.js"></script>
<script type="text/javascript">
	$(document).ready(function(){
		$("#button").click(function(){
			if($.trim($("#name").val()) == ""){
				alert("Name cannot be blank");
				return false;
			}
		});
	});
</script>
</head>
<body>
Name:<input type="text" id="name" name="name" />
<input type="button" id="button" name="button" value="Submit" />
</body>
</html>
```

----------

