Variables as objects.

Variables as objects.

I was hoping you guys could help clear something up for me.


  1. function get_states(country_element,state_element)
    {
        countryElementIDHash = "#" + country_element;
        stateElementIDHash = "#" + state_element;
        $(stateElementIDHash).empty();
                    var geonameId = $(countryElementIDHash).val();
                    $.getJSON("http://ws.geonames.org/childrenJSON?&callback=?",
                        { 'geonameId': geonameId },
                        function(data) {
                            if (data.geonames == null) alert('No regions');
                            $.each(data.geonames, function(i,item){
                                $(stateElementIDHash).append($('<option>' + item.name + '</option>'));
                            });
                        }
                    );

    }




















I'm writing a function to populate a SELECT based on the select value of another SELECT. I can't figure out why this isn't working. It has something to do with not having "'s in my $(). for example: If this function wasn't dynamic. the code: $(countryElementIDHash).val();  could simply be $("#country option:selected").val();


How can I pass dynamically assigned names into a $() ?

Thanks!