开发者

:onchange in form not working, in rails 3.1 app

开发者 https://www.devze.com 2023-04-08 20:45 出处:网络
This is exactly my problem. In my case the :onchange function is not working, though I have added the jquery in the application.rb.

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

0

精彩评论

暂无评论...
验证码 换一张
取 消

关注公众号