# Hide/Show checkbox elements based on select box - Javascript

**URL:** <https://www.ruby-forum.com/t/hide-show-checkbox-elements-based-on-select-box-javascript/132298>\
**Category:** Rails\
**Created:** [March 18, 2008, 10:42pm UTC](https://www.ruby-forum.com/t/hide-show-checkbox-elements-based-on-select-box-javascript/132298 "2008-03-18T22:42:03Z")\
**Posts on this page:** 1\
**Page:** 1

<div class="post-metadata">

**Author:** ![newrubygirl](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/n/e274bd/32.png) [@newrubygirl](https://www.ruby-forum.com/u/newrubygirl)\
**Post date:** [March 18, 2008, 10:42pm UTC](https://www.ruby-forum.com/t/hide-show-checkbox-elements-based-on-select-box-javascript/132298/1 "2008-03-18T22:42:03Z")

</div>

I have code that enables select list 1 to populate select list 2 as  
taken from a railscast. I want to change the select list 2 to a series  
of check boxes. I’m not a Javascript person so changing this is making  
a mess.

This is the 2 select list code in Javascript:

function countrySelected() {  
country\_id = $(‘fips\_code\_country\_code’).getValue();  
options = $(‘fips\_code\_state\_code’).options;  
options.length = 1;  
counties.each(function(state) {  
if (state[0] == country\_id) {  
options[options.length] = new Option(state[1], state[2]);  
}  
});  
if (options.length == 1) {  
$(‘state\_field’).hide();  
} else {  
$(‘state\_field’).show();  
}  
}

Any thoughts on how I can convert this so that the only states displayed  
in the checkbox list are those associated with the selected country? Do  
I do something with the id element? I think that I need to change line  
3 so that it’s not looking at the , but rather an id. But  
again, I have no clue what I’m doing.

Any help would be GREATLY appreciated.
