I have this code thats basically reading the dom and sending the values to the server. I am looking for any possible flaws that I may have in this javascript code and any advices to make it better and bug free!
$(document).ready(function () {
$('.editButton').click(function () {
var postData = {};
var cData = {};
cData.Balance = $(this).parent().children('.balance').text().replace("$", "");
cData.desiredStatus = $(this).parent().children('.status').text() == "Disbled" ? "enable" : "disable";
$('#currentBalance').html($(this).parent().children('.balance').text());
$('#currentStatus').html($(this).parent().children('.status').text());
$('#desiredStatus').html(cData);
//set post view
postData.code = $(this).parent().children('.code').text();
postData.giftcardaccount_id = $(this).parent().children('.giftcardaccount_id').text();
$("#dialog").dialog({
title:"test box",
modal:true,
width:700,
buttons:{
'Confirm':function () {
postData.status = $('#currentStatus').html();
var balanceInqury = parseFloat($('#desiredBlance').val());
postData.balance = (balanceInqury == 'NaN') ? cData.Balance : balanceInqury;
$.ajax({
url:'/url/to/postto',
type:'POST',
data:{
postData:postData
},
success:function (data) {
console.log(data);
$("#dialog").dialog("close");
},
error:function () {
}
});
},
Cancel:function () {
$(this).dialog("close");
}
}
});//dialog
});
$('#changeStatus').click(function () {
var c = $('#currentStatus').html() == 'Disabled' ? 'Enabled' : 'Disabled';
var d = $('#desiredStatus').html() == 'disable' ? 'enable' : 'disable';
$('#currentStatus').html(c);
$('#desiredStatus').html(d);
});
});