Check a checkbox and disable a field with Javascript

Good afternoon to you all,

I have an order form where people can check the fruits they want and
select the price of each fruit that they have checked.

When I click the checkbox now, it does not seem to affect the
corresponding price dropdown. What am I doing wrong?

Here’s the javascript:

Then, inside my loop of @fruits:
<%= fruit.name %>
<%= check_box_tag fruit.name, 1, false, :onchange =>
“toggle_fruit_price(#{fruit.name}_price);” %>
<%= select_tag("#{fruit.name}_price", options_for_select((0…100))) %>

Does anyone see what I’m doing wrong? Any help is appreciated.

On 3 Dec 2008, at 19:07, Joe P. wrote:

If you think of the javascript that will be generated it’s just going
to be

toggle_fruit_price(apple_price);

whereas you want it to be

toggle_fruit_price(‘apple_price’);

Fred

Joe P. wrote:

Good afternoon to you all,

I have an order form where people can check the fruits they want and
select the price of each fruit that they have checked.

When I click the checkbox now, it does not seem to affect the
corresponding price dropdown. What am I doing wrong?

Here’s the javascript:

Then, inside my loop of @fruits:
<%= fruit.name %>
<%= check_box_tag fruit.name, 1, false, :onchange =>
“toggle_fruit_price(#{fruit.name}_price);” %>
<%= select_tag("#{fruit.name}_price", options_for_select((0…100))) %>

Does anyone see what I’m doing wrong? Any help is appreciated.

Maybe you can try somthing like this:

if $(‘lqname’).checked == “1”
$(‘fruit_price_field’).show()

If you think of the javascript that will be generated it’s just going
to be

toggle_fruit_price(apple_price);

whereas you want it to be

toggle_fruit_price(‘apple_price’);

Fred
Hmm, well I have also tried

and that doesn’t work. I’m sure I’m only a tiny bit off, how else
should I write this?

On Dec 3, 7:19 pm, Joe P. [email protected] wrote:

Hmm, well I have also tried

and that doesn’t work. I’m sure I’m only a tiny bit off, how else
should I write this?

That wasn’t the problem - the toggle_fruit_price function was fine as
it was. The problem is with this statement

toggle_fruit_price(apple_price);

Forget that it’s js for a second - that statement isn’t legal if there
is no variable named apple_price, which there isn’t

Fred

That wasn’t the problem - the toggle_fruit_price function was fine as
it was. The problem is with this statement

toggle_fruit_price(apple_price);

Forget that it’s js for a second - that statement isn’t legal if there
is no variable named apple_price, which there isn’t

Fred

Phew, thanks. Javascript is not my forte, but I’m learning more of it
now. Thanks for the help :slight_smile: