I'm trying to detect all textboxes and dropdownlists on my page and check if they have changes upon window unload. The problem is, I can detect textboxes but not dropdownlists. Here's how I do it.
$(document).ready(function () {
var warnMessage = 'Warning: You have unsaved changes.';
$('input:not(:button,:submit),input[type="text"],select').each(function () {
var elem = $(this);
// Save current value of element
elem.data('oldVal', elem.val());
// Look for changes in the value
elem.bind("propertychange keyup input paste", function (event) {
// If value has changed...
if (elem.data('oldVal') != elem.val()) {
window.onbeforeunload = function () {
if (warnMessage != null) return warnMessage;
else warnMessage = 'Warning: You have unsaved changes.';
}
}
});
});
$('input:submit,#addLiquidFillButton,#addCommentButton,#addManualRegenButton,#addStateMileageButton').click(function (e) {
warnMessage = null;
});
});
Additional Info. I create dropdownlist using this code:
<asp:DropDownList ID="LocationIdDDL" CssClass="ddl" runat="server" AutoPostBack="true"></asp:DropDownList>
I'm assumed that by adding 'select' will check all dropdownlists, but right now, it don't. Any ideas? Thanks!