Observe_field, :function, same value

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.

On Jun 16, 7:43 pm, Spencer R. [email protected]
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

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 C. wrote:

On Jun 16, 7:43�pm, Spencer R. [email protected]
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