How do I find if a variable is undefined?
I currently have:
var page_name = $("#pageToEdit :selected").text();
var table_name = $("#pageToEdit :selected").val();
var optionResult = $("#pageToEditOptions :selected").val();
var string = "?z=z";
if ( page_name != 'undefined' ) { string += "&page_name=" + page_name; }
if ( table_name != 'undefined' ) { string += "&table_name=" + table_name; }
if ( optionResult != 'undefined' ) { string += "&optionResult=" + optionResult; }
function doesExist(el) { if((typeof el !== "undefined") && (typeof el.val() !== "undefined")){ return true; } else{ return false; } }
Then you can just call it like thisif (doesExist(variable_name)) { // do stuff }
– MistyDawn