Tuesday, June 30, 2009

[jQuery] check/uncheck all checkboxes with specific id

I want to check all of my checkboxes in my form that have an id that
begins with 'chkEvent'. Thanks

<script language="Javascript" type="text/javascript">
$(document).ready(function() {
$("#toggleEvents").click(function(event){
$('input[@type=checkbox]').each( function() {

// Begin this is where I am lost
if($(this).id()=='chkEvent*')
// End this where I am lost
this.checked = !this.checked;
});
});
});
</script>


<a href="#" id="toggleEvents">Toggle Events</a>

<form method="post" action="">
<input type="checkbox" value="EventAcceleratedOptionVesting"
id="chkEventAcceleratedOptionVesting" />
<input type="checkbox" value="AccountingChanges"
id="chkEventAccountingChanges" />
<input type="checkbox" value="AnnualMeetingChanged"
id="chkEventAnnualMeetingChanged" />
<input type="checkbox" value="AssetSalePurchase"
id="chkEventAssetSalePurchase" />
<input type="checkbox" value="AuditorChange"
id="chkEventAuditorChange" />
</form>

No comments: