I have checkboxes that toggle on/off select option values. This part works fine.
Now I want to “check” the check box after page load by default.
I tried .click() that checks the checkbox but doesn’t run the click code that is linked to it. Tested on firefox 6.0.2, Safari & Chrome. Any suggestion how to do so?
jsfiddle example is here or below
$(function(){
$selectClone = $("select[name=db2_timestamp]").clone(true);
$("input[name=hideit]").click(function(){
var $this;
$selectClone.find("option").attr("disabled", false);
$("input[name=hideit]").each(function(){
var value = $(this).attr('value');
if($(this).is(":checked")){
$selectClone.find("option").each(function(){
$this = $(this);
if($this.val().indexOf(value) != -1){
$this.attr("disabled", true);
}
});
}
})
var $select = $("select[name=db2_timestamp]")
$select.children().remove();
$selectClone.find("option:enabled").each(function(){
$select.append($(this).clone(true));
});
});
$("input[value=w]").click();
});
Move the hide/show bits into a function and call the function both in the click handler and in an initialize function. Fiddle here