In the following snippet of javascript code, there are times when html element scenario is not present on the php page. So when javascript is called, the value entered in first code line below is "undefined". As the scenario is a numeric input with default value 0, I tried to check if or not posted html element is an integer, so as to restore default value. But its not working. Please guide how to check and restore default value if html element is not present on the page. The remaining code posts the javascript variable into another php file, which updates database and it works fine when html element is actually present on the page. There are different conditions because of which the html element may or may not be present on the php page.
var scenario = $("#scenario"+tournament_id).val();
if(!isNaN(scenario))
{
scenario = 0;
}