Hey all I''m having problems getting the correct value of a checkbox. I have an observe field that calls a javascript function whenever the checkbox is changed. But for whatever reason the checkbox value always seems to be 1. Perhaps I''m using the wrong syntax to get the value?... My code is below, any help would be greatly appreciated. <% remote_form_for :nAd, @nAd, :url => { :action => "update" } do |f| %> <%= f.check_box :excludeAd %> <%= f.text_area :whyExcludeAd, :cols => 30, :rows => 5 %> <% end %> <%= observe_field("nAd_excludeAd", :function => "displayElementByValue(''nAd_excludeAd'', ''nAd_whyExcludeAd'');") %> function displayElementByValue(elementToCheck, elementToChange) { // value is always 1!! var value = $(elementToCheck).value; formElement = document.getElementById(elementToChange); } Basically when this function is called it changes the display property of the "nAd_whyExcludAd" element, however I can''t get it to correctly show the value from "nAd_excludeAd", though the function is being called correctly. -- Posted via http://www.ruby-forum.com/.
On Jun 16, 7:43 pm, Spencer Rogers <rails-mailing-l...-ARtvInVfO7ksV2N9l4h3zg@public.gmane.org> wrote:> Hey all I''m having problems getting the correct value of a checkbox. I > have an observe field that calls a javascript function whenever the > checkbox is changed. But for whatever reason the checkbox value always > seems to be 1. Perhaps I''m using the wrong syntax to get the value?... > My code is below, any help would be greatly appreciated.The value of a checkbox doesn''t change. You need to be checking whether its checked property is true (or use something like prototypes $F() method which abstracts away that sort of concern. Fred> > <% remote_form_for :nAd, @nAd, :url => { :action => "update" } do |f| %> > <%= f.check_box :excludeAd %> > <%= f.text_area :whyExcludeAd, :cols => 30, :rows => 5 %> > <% end %> > > <%= observe_field("nAd_excludeAd", :function => > "displayElementByValue(''nAd_excludeAd'', ''nAd_whyExcludeAd'');") %> > > function displayElementByValue(elementToCheck, elementToChange) > { > // value is always 1!! > var value = $(elementToCheck).value; > formElement = document.getElementById(elementToChange); > > } > > Basically when this function is called it changes the display property > of the "nAd_whyExcludAd" element, however I can''t get it to correctly > show the value from "nAd_excludeAd", though the function is being called > correctly. > -- > Posted viahttp://www.ruby-forum.com/.
Oy, that''s an awful mistake! lol It''s been a while since I''ve used checkboxes. That did the trick, thanks for the help. Frederick Cheung wrote:> On Jun 16, 7:43�pm, Spencer Rogers <rails-mailing-l...@andreas-s.net> > wrote: >> Hey all I''m having problems getting the correct value of a checkbox. �I >> have an observe field that calls a javascript function whenever the >> checkbox is changed. �But for whatever reason the checkbox value always >> seems to be 1. �Perhaps I''m using the wrong syntax to get the value?... >> My code is below, any help would be greatly appreciated. > > The value of a checkbox doesn''t change. You need to be checking > whether its checked property is true (or use something like prototypes > $F() method which abstracts away that sort of concern. > > Fred-- Posted via http://www.ruby-forum.com/.