How can I capture "undefined" in javascript?
<p>I'm working on going through all values in a form but I keep getting undefnined then my values show up.  I'm dynamically creating the form so I think the undefined maybe coming from the blank field.</p>

<p>Here's the code I'm using to get all the elements:</p>

<pre><code>//try to get all elements
var output;
$(this).parents('form') // For each element, pick the ancestor that's a form tag.
.find(':input') // Find all the input elements under those.
.each(function(i) {
    //alert(this.value+ " = " + i);
    if (typeof this.value === "undefined") {
        output = "nothing here";
    } else {
        output += this.value;
    }
});
$("div#total").append("value = " + output + "&lt;br&gt;");
</code></pre>

<p>If I enter 1,2,3,4,5,6 then my output is:</p>

<pre><code>hello value = undefined
value = undefined1
value = undefined1
value = undefined12
value = undefined12
value = undefined123
value = undefined123
value = undefined1234
value = undefined1234
value = undefined12345
value = undefined12345
value = undefined123456
</code></pre>

<p>The result is what I want except for the undefined part.  I saw this answer: <a href="http://stackoverflow.com/questions/776950/javascript-undefined-undefined">Javascript: undefined !== undefined?</a> and have tried their suggestions but I can't seem to get my program to save the value if the value is NOT undefined.  </p>

<p>If it helps here's the full code: <a href="http://jsfiddle.net/lostsoul/rKLrZ/" rel="nofollow">http://jsfiddle.net/lostsoul/rKLrZ/</a></p>
