În php I would use this to see if a variable is set and then use that value, otherwise make it a zero:
$pic_action = isset($_POST['pic_action']) ? $_POST['pic_action'] : 0;
But what is the equivalent in javascript?
I want to check if an element exists in the document, and then if it does, add it to the variable, otherwise add some other value to it, here is what I have so far:
var areaOption = document.getElementById("element");
Thanks
document.getElementById("element")will returnnullif the element doesn’t exist — and something not-nullif it exists.Which means you should be able to do something like this :
(You could also compare
areaOptionwithnull, instead of just checking if it’s non-falsy)