score:0

Instead use the builtin method like:

$('.user_form_validation').validate({
    submitHandler: function(form) {
       alert($('#user_first_name').val());
    }
});

The issue is you are placing an alert in the javascript object literal:

{
 alert($('#user_first_name').val());
}

As you have assigned the .validate() method to a jquery object and this method takes an object as an argument. Which should be an object with key and values.

score:0

Try like this.validate() function validates the form.To alert the field value.You can make use of jquery events.As below.Click the submit button..e

<script src="http://ajax.aspnetcdn.com/ajax/jquery.validate/1.11.1/jquery.validate.min.js"></script>
    <%= form_for(user, :html=>{:class=>'user_form_validation'}) do |f| %>
       <div class="field">
          <%= f.label :first_name %>
          <%= f.text_field :first_name%>
       </div>

       <div class="field">
          <%= f.label :last_name %>
          <%= f.text_field :last_name%>
       </div>
       <div class="actions">
          <%= f.submit "Create",:id => "submit_button" %>
       </div>
    <% end%>
    <script type="text/javascript">
      $(document).ready(function(){
          $('#submit_button').click(function(){
            alert($('#user_first_name').val());
          });
        });
    </script>

If you want to validate your form try like this..Fiddle http://jsfiddle.net/xs5vrrso/ AND

http://jsfiddle.net/xs5vrrso/4018/


Related Query

More Query from same tag