Here is my Jquery code:
$('#unblockButton').click(function () {
var blockedlist = [];
var count = 0;
$('#blockedList > option:selected').each(function () {
count = count + 1;
blockedlist.push(this.value);
$(this).remove();
});
unblockDistributor(blockedlist.join(', '), count)
});
<select multiple="multiple" class="listBox" name="blockedList" id="blockedList">
<option title="John Doe (3)" value="21">John Doe (3)</option>
<option title="Jane Doe (4)" value="24">Jane Doe (4)</option>
<option title="Jason Doe (5)" value="23">Jason Doe (5)</option>
</select>
What I want to do is to save myself a page refresh and remove the element in the Jquery, would be even better to do it only if the post was successful.
function unblockDistributor(ID, count) {
var distref = '<%= dictlanguage("DistributorRef") %>';
var alertStr = ''
if (count > 1) {
alertStr = 'You have removed ' + count + ' ' + distref.toLowerCase() + 's from your block list.';
} else {
alertStr = 'You have removed ' + count + ' ' + distref.toLowerCase() + ' from your block list.';
}
$.post('message_center_functions.asp', { action: "unblock", unblockID: ID }, function (data) {
})
.success(function () { alert(alertStr); })
.error(function () { alert("There was an error while trying to make this request; If it persists please contact support"); });
}
With this code it should only be removed if
$.postwas successful:http://jsfiddle.net/3TVZa/