:onchange in form not working, in rails 3.1 app
This is exactly my problem. In my case the :onchange function is not working, though I have added the jquery in the application.rb.
in the form, I need to alert the users
开发者_如何学编程<%= telephone_field(:user, :phone_country_code, :size => 1, :onchange => "if $('user[phone_country_code]').length > 2 { alert('Your firstname needs to be shorter!'); }") %>
in application.html.rb
<%= javascript_include_tag "jquery" %>
in the console I am getting
Started GET "/assets/application.js?body=1" for 127.0.0.1 at 2011-09-27 12:36:39 +0530
Served asset /application.js - 304 Not Modified (1ms)
I think you have a syntax error in your javascript. Add parentheses:
if ($('user[phone_country_code]').length > 2) { alert('Your firstname needs to be shorter!'); }")
Also: strange alert for a country code..
精彩评论