I want to assign a click handler for button in the page load function. I then want to handle the actual click of the button at a later time with the following code snippet:
$("#finish").off('click').on('click', function () {
var sku = $("#productSKU").val();
var name = $("#productName").val();
var affiliateId = $("#AffiliateID").val();
var Errors = "";
var category = null;
var defaultName = $('#defaultImgName').val();
if ($("#childCategories_" + categoryLevel).length == 0) {
category = $("#categoryList").val();
}
else if ($("#childCategories_" + categoryLevel).val() == 0) {
category = null;
}
else {
category = $("#childCategories_" + categoryLevel).val();
}
if (!sku) {
Errors += " You can not add a product without an Item Code ";
}
if (!name) {
Errors += " You can not add a product without a Name ";
}
if (!category) {
Errors += " You can not add a product without a Category ";
}
if (Errors != "") {
cua({ text: Errors, type: 'danger' })
}
else {
data.formData = { productName: name, productSKU: sku, affiliateID: affiliateId, categoryID: category, defaultImgName: defaultName }
data.submit();
}
});
How do I assign the click event handler in the page load, and then trigger the actual event of the click later on?
Reason for this is it's causing errors where the button is unresponsive if an image is not uploaded, which I found to be caused by an event handling problem.
No comments:
Post a Comment