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
Related Query
- Jquery Ajax - Uncaught SyntaxError - Unexpected token
- uncaught syntaxerror unexpected identifier at jquery ajax url
- uncaught syntaxerror unexpected string
- Jquery getJSON Uncaught SyntaxError: Unexpected token : error
- jQuery Uncaught SyntaxError: Unexpected Identifier but my code looks good! (I think)
- Read news from feed using jquery (cross domain), Getting Uncaught SyntaxError: Unexpected token < error
- Uncaught SyntaxError Unexpected Number JSON.parse
- Uncaught SyntaxError: Unexpected string
- jQuery - Uncaught SyntaxError: Unexpected token )
- Wordpress jQuery Uncaught SyntaxError: Unexpected token ILLEGAL
- Uncaught SyntaxError in jQuery
- Uncaught SyntaxError: Unexpected token : jQuery ajax
- jquery Uncaught SyntaxError: Unexpected token -
- Facebook jQuery AJAX JSON call - Uncaught SyntaxError: Unexpected token :
- Uncaught SyntaxError jQuery
- Uncaught SyntaxError : Unexpected token ;
- Jquery ajax syntaxerror json.parse unexpected character at line 1 column 1 of the json data
- Uncaught SyntaxError: Unexpected token x with jQuery plugin?
- jquery cookie set throwing unexpected string error
- .animate in jQuery giving unexpected results
- Getting empty string instead of undefined from unset attributes using jQuery
- ASP.NET MVC + sending encoded string using jquery ajax
- Sending string to wcf service using jquery ajax. why can i only send strings of numbers?
- jQuery through NuGet on MVC 4 producing an unexpected URL path
- Uncaught Error: Invariant Violation: Element type is invalid: expected a string
- jQuery String Replace in TextArea
- jQuery this.href String Comparison Not Working
- How to substring the string using jQuery
- jquery ending string at space
- print Jquery string values inside html
- Why can't I use `this` in $.each function as string arg for jQuery function
- get string between two strings using jquery
- Get Second to last character position from string using jQuery
- replace part of a string using jquery
- regex or jquery to split string after certain character
- quantity of white spaces left of a string jQuery
- Adding special characters to a String using jQuery
- Jquery to parse HTML in a string
- Jquery find: Uncaught TypeError: row.find is not a function
- String to array and take individual value in jquery
- jQuery html() not working for string
- Calculate with string jQuery
- Javascript Variable within jQuery string
- jQuery Template, {{if}} with a passed string
- jQuery Datatables large data set Uncaught TypeError: Cannot read property 'mData' of undefined
- How to modify html string using jQuery
- jQuery showing empty string on input text?
- Iterating through table using jquery gives uncaught exception
- Extract number from string with jquery
- jquery html doesn't add the entire string
More Query from same tag
- Javascript Library for Dynamic HTML Table Generation
- AJAX: error (deprecated!) works while fails doesn't. Why?
- jQuery scrollTop() returns zero for any element
- Need help understanding jQuery functions
- $f is undefined for Flowplayer instance
- jQuery Cycle Plugin not displaying a slideshow
- Sending multiple images with AJAX
- How do i fade out a pop up box when the body behind it is clicked
- To keep checkbox checked after save
- How to programatically call jquery datepicker select
- Kineticjs Group Image dragging
- arrow keys not scrolling on IE7 for our web site
- Twitter Bootstrap 3 - dropdown menu in nav-collapse
- check if radio button is not empty
- I am trying to show a logo when the page scroll > 920
- How can I separate words in td with an html tag?
- best way to remove the span tags without removing the inner text
- JQuery not working if only 2 of 3 Ajax returns are Json
- can't get fancybox helper buttons to show
- How to get folder path instead of file path in extjs
- Bootstraps table lines disappearing when used with popovers
- Is it possible to bring up the device's Number keypad on DIV click?
- document ready, $(document).on("yyy") and function ondeviceready()
- jquery write a style using variable
- JQuery - trying to change/update value on click and also pass full value text, but only add number
- javascript, jQuery, Ajax Autocomplete
- How to escape double image loading?
- How to hide table row using Jquery hide option
- How plot json data
- jQuery/ajax is not updating divs on the page