Also,

The markup generated by rails for forms has enough information to bind
events unobtrusively.  In other words, do what erik said, and do it in a
script block or file so that it keeps your erb as erb.

  $("#contact_can_call").change(function(item) {
    if(item.target.checked) {
      alert("Yay, it's checked");
    } else {
      alert("Boo, it's not");
    }
  });

--Dan

On Thu, Oct 7, 2010 at 9:30 AM, Erik Pukinskis <[email protected]>wrote:

> Not sure if this is your issue, but you should try:
>
>  ('contact_phonenumber').attr('disabled', $('contact_can_call').checked);
>
> In general with jQuery I lean towards using attr instead of accessing
> things directly.  Although the .checked/value/etc of input elements is
> an exception.
>
> Best,
> Erik
>
> On Sat, Sep 25, 2010 at 11:57 AM, joshua <[email protected]> wrote:
> > Hi,
> >
> > I am trying to figure out the syntax to enable text field based on
> > checkbox selection. Your help is greatly appreciated.
> >
> > What is wrong with the following definition?
> >
> > <% form_for(@contact) do |f| %>
> > ...
> >  <p>
> >    <%= f.label :can_call %><br />
> >    <%= f.check_box :can_call, :onclick => "$
> > ('contact_phonenumber').disabled = $
> > ('contact_can_call').checked;", :onchange => "$
> > ('contact_phonenumber').disabled = $('contact_can_call').checked;" %>
> >  </p>
> >  <p>
> >    <%= f.label :phonenumber %><br />
> >    <%= f.text_field :phonenumber, :size => 80, :maxlength =>
> > 20, :disabled => "$('contact_can_call').checked?false:true;" %>
> >  </p>
> >  ...
> > <% end %>
> >
> > Thanks,
> >
> > Josh
> >
> > --
> > SD Ruby mailing list
> > [email protected]
> > http://groups.google.com/group/sdruby
>
> --
> SD Ruby mailing list
> [email protected]
> http://groups.google.com/group/sdruby
>

-- 
SD Ruby mailing list
[email protected]
http://groups.google.com/group/sdruby

Reply via email to