0

I am using Twitter Bootstrap too (for the first time). Here is minimized code so you can help me determine why it's not even going to validate function! I've been working for hours now, I don't know what I am missing. Validate.js is downloaded from official plugin site but it's same if I use from cdn.

<head>
<link rel="stylesheet" href="css/bootstrap.css"  type="text/css"/>
<script type="text/javascript" src="http://code.jquery.com/jquery-1.8.3.min.js"></script>
<script type="text/javascript" src="js/jquery.validate.min.js"></script>
<script type="text/javascript" src="js/bootstrap.js"></script>

    <script>
    $().ready(function() {
          $("#myform").validate({
             rules: {
                 InputName: {
                    required: true
                }
             }
          });
    });
</script>
</head>

<body>
<div class="container">
    <div class="row">
        <div class="col-md-4 col-md-offset-4">

            <form name="myform" id="myform" method="post" action="">
                <label class="control-label" for="InputName">Name:</label>
                <input type="text" class="form-control" name="InputName" placeholder="ex. John">    

            <button type="submit" class="btn btn-default">Submit</button>
            </form>


        </div>
    </div>
</div>

</body>
3
  • try jsfiddle.net/arunpjohny/jcaT4/1 Commented Nov 26, 2013 at 10:16
  • <center> tag was deprecated years ago! Commented Nov 26, 2013 at 14:59
  • Are you getting any console errors? Are you sure the scripts are properly included? Commented Nov 26, 2013 at 16:54

5 Answers 5

1

1) <center> was deprecated many years ago. Use CSS instead.

2) ().ready(function({...})) is not recommended as per jQuery documentation. Use $(document).ready(function({...})) or $(function({...})) instead.

However, your code is working exactly as you posted it.

DEMO: http://jsfiddle.net/FbAYz/

Sign up to request clarification or add additional context in comments.

4 Comments

You have any idea why not working on my server then?
@mortusdetus, how could I know anything about your server? I can only go with what you've posted in your OP. Are you getting any JavaScript errors? Did you properly include the files? Did you upload them? Are the file paths correct?
Maybe you have an idea because I certainly don't. If I use cdn links it's the same thing so not about including properly.
@mortusdetus, I don't have access to your server but since JavaScript runs in the client, the problem probably has nothing to do with your server. Again, for the third time, do you have any JavaScript errors in your console?
1

Must use https for src links instead of http.

Comments

1

Removing a css class name from my form markup resolved a similar issue I was going through.

I had a class "validate-form" in the <form> tag.

Comments

0

Try to use this

<script>
    $(document).ready(function() {
          $("#myform").validate({
             rules: {
                 InputName: {
                    required: true
                }
             }
          });
    });
</script>
/*Instead of */

  <script>
    $().ready(function() {
          $("#myform").validate({
             rules: {
                 InputName: {
                    required: true
                }
             }
          });
    });
</script>

Comments

0

If everything is correct but still no validation is happening then Try to use the debug:true option

$("#myForm").validate({
  debug: true
});

Reload the page and check the console for any possible errors``

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.