I did a search and found a reference to what I need help with but it doesn't seem to work for me. I'm having trouble getting a value for a checkbox and testing it in my controller. (I'm not sure what the problem is since I have no trouble getting the other form field values.) Some help in what I'm doing wrong would greatly be appreciated.
The form contains a field like so: <input type="checkbox" name="different_billing_info" id="different_billing_info" value="1" onclick="changedDifferentBillingAddress(this)"> different billing address
In my controller I reference it like so: billing_address_hash = Hash.new() if (params[:different_billing_info] == "1") billing_address_hash.merge(params[:billing_address]) else billing_address_hash.merge(params[:customer]) # Remove customer fields not found in the billing address table billing_address_hash.delete('uva_status') billing_address_hash.delete('email') end
I saw a prior posting to getting the checkbox value with a checked associative array index, ie. if (params[:different_billing_info]['checked'] == "1")
But this seemed to make no difference. No matter what the value of the checkbox is, the first part of the if statement above is executed.
I even tried adding a hidden field to the form based on an example I saw: <input type="checkbox" name="different_billing_info" id="different_billing_info" value="1" onclick="changedDifferentBillingAddress(this)"> different billing address <input type="hidden" name="different_billing_info" value="0"><!-- hidden billing info field used to pass a value regardless of whether box is checked or not -->
which does in fact have the value passed be either 1 or 0 depending on if it is checked or not. I see this in looking at the contents of the Parameters hash.
Thoughts?
Thanks, Jack