How to get the value of a datetime_select field with javascript in ruby on rails

爷,独闯天下 提交于 2019-12-08 05:13:25

问题


I had a previous question that touched this topic (Rails: how to get value from another field when executing an onchange remote function in textfield), but then I dugg a little deeper and realized that my problem is the datetime_select method.

I have a textfield with onchange. In the onchange I need to get the value of a datetime_select field to pass as a parameter when making the ajax call to my controller. The first thing to note is that a datetime_select is actually composed of five dropdowns (year, month, day, hour and minute), so I need to get the values of each of them separately (I presume, is there a simpler way?). But when I try to get their value with code like:

$(model + '_' + attribute + '_3i').value  

which should return the value of the "day" dropdown I get an error: "TypeError: $("model_attribute_3i").value.toS is not a function"

If I create all the dropdowns for the datetime objects manually the same call works just fine. So there seems to be some magic in the way a datetime_select is composed that prevents me from asking the value of the dropdowns. Is there any way to go around this or do I just have to recode the datetime_select functionality in my application?


回答1:


Problem seems to be solved for now, problem was me being a javascript n00b... apparently I used same variable names in too many places which leaded to weird behavior.



来源:https://stackoverflow.com/questions/1136688/how-to-get-the-value-of-a-datetime-select-field-with-javascript-in-ruby-on-rails

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!