# jQuery with Rails

**URL:** <https://www.ruby-forum.com/t/jquery-with-rails/156298>\
**Category:** Rails\
**Created:** [December 24, 2008, 4:02am UTC](https://www.ruby-forum.com/t/jquery-with-rails/156298 "2008-12-24T04:02:40Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![bruparel](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/b/e47774/32.png) [@bruparel](https://www.ruby-forum.com/u/bruparel)\
**Post date:** [December 24, 2008, 4:02am UTC](https://www.ruby-forum.com/t/jquery-with-rails/156298/1 "2008-12-24T04:02:40Z")

</div>

In a nutshell, my jQuery code in a rails form works in Firefox, but not  
in Internet Explorer 7. Here is the form code with unnecessary details  
stripped out:

# New Discount Order

\<%= error\_messages\_for :discount\_order %\> \<% vertical\_form\_for :discount\_order, @discount\_order, :url =\> discount\_orders\_path, :method =\> :post do |f| %\> \<% f.radio\_button\_group :code\_type, :label =\> 'Code Type', :id =\> 'ctype' do %\> \<%= f.radio\_button :code\_type, 'voucher', :label =\> 'Single-use vouchers', :button\_on\_left =\> true %\>  
 \<% if @who == 'partner' %\> \<%= f.radio\_button :code\_type, 'affiliate', :label =\> 'Multi-use affiliate', :button\_on\_left =\> true %\> \<% end %\> \<% end %\> \<%= f.text\_field :requested\_codes, :size =\> 2, :label =\> "How Many Codes", :help =\> 'Number of codes to generate. Only applies to single-use codes.'%\> \<% f.wide\_content :id =\> 'has\_expiration\_date' do %\> \<%= check\_box\_tag :has\_expiration\_dates, '1', !@discount\_order.codes\_expire\_at.blank? %\>Codes Expire? \<% end %\> \<%= f.date\_field :codes\_expire\_at, :label =\> 'Expiration Date', :disabled =\> @discount\_order.codes\_expire\_at.blank? %\> \<%= f.submit 'Create', :cancel =\> {:controller =\> 'system', :action =\> 'discounts'}%\> \<% end %\>

Does anyone know a cross platform (Firefox and IE) solution to above?

Thanks for your time.

Bharat

---

<div class="post-metadata">

**Author:** ![bruparel](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/b/e47774/32.png) [@bruparel](https://www.ruby-forum.com/u/bruparel)\
**Post date:** [December 25, 2008, 12:58am UTC](https://www.ruby-forum.com/t/jquery-with-rails/156298/2 "2008-12-25T00:58:18Z")

</div>

The problem is solved. I changed the “change” event to “clicked” event  
as shown below:

jQuery(function(){  
jQuery(’#has\_expiration\_date input’).change(function(){  
jQuery(’#discount\_order\_\_codes\_expire\_at’).attr(‘disabled’,  
!jQuery(’#discount\_order\_\_codes\_expire\_at’).attr(‘disabled’))  
});  
jQuery(’#ctype’).clicked(function(){ \<------ changed from “change”  
event  
jQuery(’#discount\_order\_\_requested\_codes’).attr(‘disabled’,  
!jQuery(’#discount\_order\_\_requested\_codes’).attr(‘disabled’));  
if (jQuery(’#discount\_order\_\_code\_type\_affiliate:checked’).val() ==  
‘affiliate’) {  
jQuery(’#discount\_order\_\_requested\_codes’).val("")  
}  
})  
})

I got this tip from the jQuery in Action book written by Bear Bibeault  
and Yehuda K… They document it on page 114. Thank you gentlemen.

One thing that I am learning as a new Javascript/jQuery developer is  
that not everything works in a cross-platform manner even in a  
supposedly cross-browser library as jQuery.

Bharat

---

<div class="post-metadata">

**Author:** ![bruparel](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/b/e47774/32.png) [@bruparel](https://www.ruby-forum.com/u/bruparel)\
**Post date:** [December 25, 2008, 7:18am UTC](https://www.ruby-forum.com/t/jquery-with-rails/156298/3 "2008-12-25T07:18:16Z")

</div>

Bharat R. wrote:

> The problem is solved. I changed the “change” event to “clicked” event  
> as shown below:
> 
> jQuery(function(){  
> jQuery(’#has\_expiration\_date input’).change(function(){  
> jQuery(’#discount\_order\_\_codes\_expire\_at’).attr(‘disabled’,  
> !jQuery(’#discount\_order\_\_codes\_expire\_at’).attr(‘disabled’))  
> });  
> jQuery(’#ctype’).clicked(function(){ \<------ changed from “change”  
> event  
> jQuery(’#discount\_order\_\_requested\_codes’).attr(‘disabled’,  
> !jQuery(’#discount\_order\_\_requested\_codes’).attr(‘disabled’));  
> if (jQuery(’#discount\_order\_\_code\_type\_affiliate:checked’).val() ==  
> ‘affiliate’) {  
> jQuery(’#discount\_order\_\_requested\_codes’).val("")  
> }  
> })  
> })
> 
> I got this tip from the jQuery in Action book written by Bear Bibeault  
> and Yehuda K… They document it on page 114. Thank you gentlemen.
> 
> One thing that I am learning as a new Javascript/jQuery developer is  
> that not everything works in a cross-platform manner even in a  
> supposedly cross-browser library as jQuery.
> 
> Bharat

mostly try to avoid Jquery.  
if you Jquery some functions prototype won’t work.  
I have faced this problem earlier.
