Skip to content

Instantly share code, notes, and snippets.

@pebriana
Created October 18, 2016 05:50
Show Gist options
  • Save pebriana/3e91dc7ca3bf6307d4d43993d4e84265 to your computer and use it in GitHub Desktop.
Save pebriana/3e91dc7ca3bf6307d4d43993d4e84265 to your computer and use it in GitHub Desktop.
checkbox checked if the values in array
<table>
<tr>
<td width="3%"></td>
<td>
<input class="weekdays" type="checkbox" name="weeklyDay" id="sunday" value="sunday">Sunday</td>
<td>
<input class="weekdays" type="checkbox" name="Day" id="monday" value="monday">Monday</td>
<td>
<input class="weekdays" type="checkbox" name="Day" id="tuesday" value="tuesday">Tuesday</td>
<td>
<input class="weekdays" type="checkbox" name="Day" id="wednesday" value="wednesday">Wednesday</td>
</tr>
<tr>
<td width="3%"></td>
<td>
<input class="weekdays" type="checkbox" name="Day" id="thursday" value="thursday">Thursday</td>
<td>
<input class="weekdays" type="checkbox" name="Day" id="friday" value="friday">Friday</td>
<td>
<input class="weekdays" type="checkbox" name="Day" id="saturday" value="saturday">Saturday</td>
</tr>
</table>
var weekArray = ["saturday","monday","tuesday","friday" ];
$('.weekdays').filter(function () {
if (weekArray.indexOf(this.id) != -1)
return $(this).closest('td').find(':checkbox');
}).prop("checked", true);
http://jsfiddle.net/5xkJp/
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment