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: <script type="text/javascript"> function toggle_fruit_price(lqname) {     $(lqname).disabled = (!$(lqname).disabled);   } </script>

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.

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: <script type="text/javascript"> function toggle_fruit_price(lqname) {    $(lqname).disabled = (!$(lqname).disabled); } </script>

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))) %>

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

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 <script type="text/javascript"> function toggle_weight_boxes(lqname) {     $('lqname').disabled = (!$('lqname').disabled);   } </script>

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

Joe Peck 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: <script type="text/javascript"> function toggle_fruit_price(lqname) {     $(lqname).disabled = (!$(lqname).disabled);   } </script>

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 <script type="text/javascript"> function toggle_weight_boxes(lqname) { $('lqname').disabled = (!$('lqname').disabled); } </script>

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