Quantcast
Channel: VBForums - jQuery
Viewing all articles
Browse latest Browse all 58

[RESOLVED] Validation for blank input field

$
0
0
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 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.

Viewing all articles
Browse latest Browse all 58

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>