I have ~20 variables that I want to check whether they are empty or not. Instead of writing "ugly code" in form of individual if (!a) { var a = 'N/A' }
statements, I was wondering if there is some form of shorthand similar to PHP?
I want to check if the variable is empty, and if it is, set its value to 'N/A'.
Edit: In reference to what I mean regarding PHP shorthand, I am looking for something like this.
$is_admin = ($user['permissions'] == 'admin') ? true : false;
Following the suggestion to keep variables in an array, please see my code below. I am pulling data via AJAX from my MySQL database and am outputting it as part of the data[]
array. How would I go about checking if any of the data
variables have value or not?
$.ajax({ // launch AJAX connection
type: 'POST', // via protocol POST
url: '../../plugins/MySQL/ajax_action.php',
data: { action: 'opera_lookup' , holidex: '<?php echo($_SESSION['Holidex']); ?>' , conf_no: $("#room").val() }, // send $_POST string
dataType: 'json', // encode with JSON
success: function (data)
{
var data0 = data[0];
// 20 more variables here...
},
});