Ok, assuming you read post #1, this is the jQuery option. If you havent read my previous post please do so now.
Before we start, note I run jQuery in no conflict mode so I can use prototype sometimes for existing code. To do this, I do:
<script type="text/javascript">
var $j = jQuery.noConflict();
</script>
If you dont need no conflict mode, you can just remove the j after each $ in the examples below
Im going to go through the steps that are differnt
Step 1 - No change
Step 2 - No need for the onchange, remove it this time and add the jQuery Listener
From:
<%= f.select :brand_id,
options_from_collection_for_select(@all_brands, 'id', 'name', @brand_report_source_credential_key.brand_id),{},
:onChange => remote_function(:url=> {:action=> :credential_list_for_brand},
:with=> "'brand_id=' + this.value" ) %>
To:
<%= f.select :brand_id,
options_from_collection_for_select(@all_brands, 'id', 'name', @brand_report_source_credential_key.brand_id),{} %>
Add: (to appliation.js or your other .js file)
jQuery.ajaxSetup({
'beforeSend': function(xhr) {xhr.setRequestHeader("Accept", "text/javascript")}
})
$j(document).ready(function() {
$j("#brand_report_source_credential_key_brand_id").change(function(){
$j.post("/brand_report_source_credential_keys/credential_list_for_brand", {"brand_id":$j(this).val()}, function(result) {
});
});
})
Step 3 - No Change
Step 4 - Remove the rjs file and add credential_list_for_brand.js.erb
$j("#source_credential_list").html("<%= escape_javascript(render(:partial => 'source_credential_list')) %>");
Thats it, jQuery is cool also!
Comments