Thank you for your reply, Peter. The check boxes are being renamed by
the erb, I think. Each checkbox has an ID value which is used to update
a db (via an api). The erb is appending the value to the name and,
you’re right, I think that is going to be unrecognizable to the
javascript code. I need to figure out a way to get those values into
the params hash which is passed back to the controller.
Is there another way to create these check boxes with erb that won’t
produce HTML with with the ID appended to the name?
I’lll do as you suggested and post this question at comp.lang.javascript
also. Thanks again!
BTW, You might be interested in this page for using tags and attributes
etc.
If you want to get into JavaScript stuff you might be interested in
JavaScript The Definitive Guide 4th edition by David Flanagan (O’Reilly)
to get started.
For your example to work with the Thacker script you cannot use
“add_visit_for_this_Pt[1]” etc because when the script searches for
document.myform.add_visit_for_this_Pt it will not find anything. There
isn’t an element or list of elements with the “name
add_visit_for_this_Pt”. There is an element with name
“add_visit_for_this_Pt[1]”. This is a bit subtle. Study the working
example below and see if you can make sense if it. I think that
“add_vista_for_this_Pt[1]” and “add_vista_for_this_Pt[2]” are not seen
by the JavaScript as elements of an array. However if you have multiple
checkboxes with the name “add_vista_for_this_Pt” then javascript sees
them all as part of an array.
Setting the checked attribute to true or false seems to work.
Also this is a perfect question for comp.lang.javascript since this is
not as much a Rails or Ruby question as it is JavaScript.
I guess you will have to play more with this to get it working the way
you want to with Rails.
Thank you for your reply, Peter. The check boxes are being renamed by
the erb, I think.
Yes
Each checkbox has an ID value which is used to update
a db (via an api). The erb is appending the value to the name and,
you’re right, I think that is going to be unrecognizable to the
javascript code. I need to figure out a way to get those values into
the params hash which is passed back to the controller.
Is there another way to create these check boxes with erb that won’t
produce HTML with with the ID appended to the name?
Actually you want the ID appended by the select_tag helper because it
makes processing the submitted data easier. What you probably want to
do is write new JavaScript that uses a regular expression to find the
checkboxes of interest.
I’lll do as you suggested and post this question at comp.lang.javascript
also. Thanks again!
They like one question at a time there and try to simplify it as much
as possible to show you’ve worked on the question as much as you can.
Peter
This forum is not affiliated to the Ruby language, Ruby on Rails framework, nor any Ruby applications discussed here.