I have a table with a structure similar to the following:
<tbody>
<tr class="classRow" bgcolor="#EFE5D3" style="font-weight: bold; font-size: 1.1em;">
<td width="35px"><a class="classEditLink" name="33" href="#">Edit</a></td>
<td width="20px"><input type="checkbox" class="chkDeleteClass" name="deleteClasses[]" value="33" /></td>
<td>CLASS1234</td>
<td>A Sample Class</td>
</tr>
<tr class="classDocsRow">
<td></td>
<td align="right"><input type="checkbox" class="chkRemoveDocs" name="removeDocs[]" value="38-33" /></td>
<td width="245px">Document 1</td>
<td width="600px">A Sample Document</td>
</tr>
</tbody>
<tbody>
<tr class="classRow" bgcolor="#EFE5D3" style="font-weight: bold; font-size: 1.1em;">
<td width="35px"><a class="classEditLink" name="45" href="#">Edit</a></td>
<td width="20px"><input type="checkbox" class="chkDeleteClass" name="deleteClasses[]" value="45" /></td>
<td>CLASS987</td>
<开发者_如何学Go;td>Another Sample Class</td>
</tr>
<tr class="classDocsRow noDocs">
<td colspan="4">
<strong>No documents are currently associated with this class.</strong>
</td>
</tr>
</tbody>
I also have a dropdown that looks like this:
<select type="select" id="classesList" name="classesList">
<option id="defaultClassesListItem" value="0">Select a Class...</option>
<option value="33">CLASS1234 - A Sample Class</option>
<option value="45">CLASS987 - Another Sample Class</option>
</select>
As you can see, the dropdown is a list of the classes in the table.
Using jQuery, I need to remove any items from the dropdown that are checked in the table.
I have a selector elsewhere in the site that finds the checked items in the table, like this:
$('#classesTable input[name="deleteClasses[]"]:checked')
So I figure that's a starting point. I'm assuming I need to do something like get the checked item's name value (which is the class's ID), and find that in the dropdown and remove items based on that. How can I do that?
in order to remove an item you should do something like this:
Remove an option :
$("#classesList option[value='33']").remove();
new
$('#classesTable input[name="deleteClasses[]"]:checked').each(function(){
get values to remove and delete throught something like $(this).val()
$("#classesList option[value='values']").remove();
});
Here is code for delete checked item:
function submitForm() {
var submitForm = false;
$( '.cb-element' ).each(function () {
if($(this).is(':checked')){
submitForm = true;
}
});
if(submitForm){
if (confirm("Are you sure you want to delete")) {
document.forms["myform"].submit();
} else {
return false;
}
} else {
alert('Please select an email to delete!');
}
}
精彩评论