Try
$(function () {
function select(choice) {
$('#plan').val(choice);
$tables.removeClass('plan_chosen');
$('#' + choice).addClass('plan_chosen');
}
var $tables = $('.pricing-table').click(function () {
var choice = this.id;
select(this.id)
});
$('#plan').change(function () {
select(this.value)
})
});
Demo: Fiddle
- you need to use
choice
as a variable and use it for string concatenation - you need to remove the
plan_chosen
class from previously selected element - you need to have a change handler for the select which will do the same