Forum Moderators: open
// uses jQuery to get form values
setObj = {
username : $('#username').val(),
price : $('input[name=price]').val(),
subject : $('input[name=subject]').val() || $('input[name=ad_title]').val(),
comment : $('#comment').html() || $('#commentText').val()
}; if (Object.values(setObj).length > 0) { ... } if (setObj.price + setObj.subject + setObj.comment === '') { ... } if (
// this line can become a real issue if I add more keys later and forget to modify it
setObj.price + setObj.subject + setObj.comment === 'undefinedundefinedundefined' ||
setObj.price + setObj.subject + setObj.comment === 'NaN' ||
setObj.price + setObj.subject + setObj.comment === ''
) { ... }
this line can become a real issue if I add more keys later and forget to modify it
for (let value of Object.values(setObj)) {
...
}
for (var x in setObj) { setObj[x] = isNotEmpty(setObj[x]); }
if (setObj.price + setObj.subject + setObj.comment === '') { ... }
function isNotEmpty(v) {
return (v === undefined || v === null) ?
'' :
v.toString().trim();
}