Reputation: 21
My code is only let checkbox checked,I want it also do onclick event.
<input type="checkbox" name="list" id="mycheckbox" onclick="check_marker(this)" />
document.getElementById(mycheckbox).checked = true;//I want also do onclick event.
function check_marker(input_var){
var carId;
carId = input_var.id;
alert(carId);
}
Upvotes: 0
Views: 917
Reputation: 78650
Changes made through javascript do not trigger handlers. You will need to call it yourself after making the change:
var cb = document.getElementById("mycheckbox");
cb.checked = true;
cb.onclick(); // call the click handler directly
Upvotes: 1