My question is very similar to this one: Getting an error in jQuery when I try to autosave a form field with an ajax call
But the only problem with me is that my situation is more complex. I have a form which has 2 sections. To each section the user can add rows while inputting their data. Each row has a text field and a select box. I need to update the database values of these text fields and select boxes as they change.
Since these all are added on the fly, their ids are different. Ideally I would like to u开发者_StackOverflow中文版se onchange for each textfield and select box and call required functions which will make ajax call to update respective values. But when I try calling a function onchange, nothing happens. I am wondering if this use is deprecated in Rails 3 in favour of unobtrusive js. Here's how my haml for the textfield looks:
= builder.text_field "regular_expenditure", :value => val, :title => builder.object.regular_expenditure > 0 ? "" : '0.00', :size => 7, :class => "defaultText", :onchange => "javascript:sendGivenupAmount('challenge_givenup_items_attributes_#{@given_up.rindex(given_up)}_regular_expenditure', '#{given_up.id}');"
In my js file:
function sendGivenupAmount(){
alert('in function');
}
Am I doing something wrong? Is there any other way to do this? Thanks in advance for any help
M
Thanks for the support. I think I found a solution. I just made some changes to the view and accessed the elements through DOM in jquery. I could manage getting around it.
Thanks, M
精彩评论