JavaScript: Finding whether first child of a form input is an input box or select dropdown
<p>I am trying to write a script on a form that searches within the HTML for a DD tag.  When it finds the tag I want to detect whether the first child contained in the DD tag is an input box or select box and if it to set the focus to it.  There could potentially be more than DD tag on one page so I am only concerned with the first instance of it.</p>

<p>Essentially, what I am trying to do is when the page loads, it focuses on the first form field on the page so that the user can enter data directly without the need to click on a box or dropdown.  I need he logic to be written in pure JS (so not JQuery solutions please) and to accommodate if a given page might have an input box as the first field or a select box as the first field.</p>

<p>JSFiddle: <a href="http://jsfiddle.net/3UqSq/" rel="nofollow">http://jsfiddle.net/3UqSq/</a></p>

<p>Any help would be great!</p>

<p>The HTML for input box:</p>

<pre><code>  &lt;div class="container"&gt;
     &lt;form class="myform"&gt;
       &lt;fieldset&gt;
          &lt;dl&gt;
            &lt;dt&gt;&lt;label for="input1"&gt;Label 1&lt;/label&gt;&lt;/dt&gt;
            &lt;dd&gt;
               &lt;input id="input1" type="text" value=""/&gt;
               &lt;div&gt;This is some extra DIV's for copy&lt;/div&gt;
               &lt;div&gt;This is some extra DIV's for copy&lt;/div&gt;
               &lt;div&gt;This is some extra DIV's for copy&lt;/div&gt;
            &lt;/dd&gt;
            &lt;dt&gt;&lt;label for="input2"&gt;Label 2&lt;/label&gt;&lt;/dt&gt;
            &lt;dd&gt;
               &lt;input id="input2" type="text" value=""/&gt;
               &lt;div&gt;This is some extra DIV's for copy&lt;/div&gt;
               &lt;div&gt;This is some extra DIV's for copy&lt;/div&gt;
               &lt;div&gt;This is some extra DIV's for copy&lt;/div&gt;
            &lt;/dd&gt;
         &lt;/dl&gt;
       &lt;/fieldset&gt;
     &lt;/form&gt;
   &lt;/div&gt;
</code></pre>

<p>The HTML for select box:</p>

<pre><code>  &lt;div class="container"&gt;
     &lt;form class="myform"&gt;
       &lt;fieldset&gt;
          &lt;dl&gt;
            &lt;dt&gt;&lt;label for="input1"&gt;Label 1&lt;/label&gt;&lt;/dt&gt;
            &lt;dd&gt;
               &lt;select id="input1"&gt;
                 &lt;option&gt;Option 1&lt;/option&gt;
                 &lt;option&gt;Option 2&lt;/option&gt;
                 &lt;option&gt;Option 3&lt;/option&gt;
               &lt;/select&gt;
               &lt;div&gt;This is some extra DIV's for copy&lt;/div&gt;
               &lt;div&gt;This is some extra DIV's for copy&lt;/div&gt;
               &lt;div&gt;This is some extra DIV's for copy&lt;/div&gt;
            &lt;/dd&gt;
            &lt;dt&gt;&lt;label for="input2"&gt;Label 2&lt;/label&gt;&lt;/dt&gt;
            &lt;dd&gt;
               &lt;input id="input2" type="text" value=""/&gt;
               &lt;div&gt;This is some extra DIV's for copy&lt;/div&gt;
               &lt;div&gt;This is some extra DIV's for copy&lt;/div&gt;
               &lt;div&gt;This is some extra DIV's for copy&lt;/div&gt;
            &lt;/dd&gt;
         &lt;/dl&gt;
       &lt;/fieldset&gt;
     &lt;/form&gt;
   &lt;/div&gt;
</code></pre>
