title: How to focus on first input box in dialog box
body: <p>I have following test html files, which I stripped unnecessary tags from them</p>
  
  <p><strong>dialogTest.htm</strong></p>
  
  <pre><code>&lt;!DOCTYPE&gt;
  &lt;html&gt;
  &lt;head&gt;
      &lt;link rel="stylesheet" type="text/css" href="../theme/blitzer.css" /&gt;
      &lt;script type="text/javascript" src="../js/jquery-1.10.2.min.js"&gt;&lt;/script&gt;
      &lt;script type="text/javascript" src="../js/jquery-ui-1.10.3.custom.min.js"&gt;&lt;/script&gt;
      &lt;script type="text/javascript"&gt;
          $(function () {
  
              $("#dlg").dialog({
                  autoOpen: false,
                  resizable: false,
                  modal: true
              });
  
              $('#button1').click(function () {
                  ChangePassword();
              });
  
          });
  
          var loadedByFunction = false;
  
          function ChangePassword() {
              loadedByFunction = true;
              $("#dlg").dialog('option', {
                  width: 380,
                  height: 300,
                  title: 'Change Password',
                  close: function (event, ui) {}
              });
              $('#dlg').children().attr('src', 'dialogContent.htm')
              .load(function () {
                  if (loadedByFunction) {
                      loadedByFunction = false;
                      $("#dlg").dialog('open');
                  }
              });
              return false;
          }
      &lt;/script&gt;
  &lt;/head&gt;
  &lt;body&gt;
      &lt;div style="display: none"&gt;
          &lt;div id="dlg"&gt;
              &lt;iframe src="" &gt;&lt;/iframe&gt;
          &lt;/div&gt;
      &lt;/div&gt;
      &lt;button type="button" name="button1" id="button1" &gt;Change Password&lt;/button&gt;
  &lt;/body&gt;
  &lt;/html&gt;
  </code></pre>
  
  <p>And <strong>dialogContent.htm</strong></p>
  
  <pre><code>&lt;!DOCTYPE&gt;
  &lt;html&gt;
  &lt;head&gt;
      &lt;script type="text/javascript"&gt;
          $(function () {
              $("input[name='password']").focus();
          });
      &lt;/script&gt;
  &lt;/head&gt;
  &lt;body&gt;
      &lt;form id="form1" runat="server"&gt;
      &lt;div&gt;
          &lt;table cellpadding="1" cellspacing="0" border="0"&gt;
              &lt;tr&gt;
                  &lt;td&gt;Password&lt;/td&gt;
                  &lt;td&gt;&lt;input type="password" name="password" /&gt;&lt;/td&gt;
              &lt;/tr&gt;
              &lt;tr&gt;
                  &lt;td&gt;New Password&lt;/td&gt;
                  &lt;td&gt;&lt;input type="password" name="password1" /&gt;&lt;/td&gt;
              &lt;/tr&gt;
              &lt;tr&gt;
                  &lt;td&gt;&amp;nbsp;&lt;/td&gt;
                  &lt;td&gt;&lt;input type="password" name="password2" /&gt;&lt;/td&gt;
              &lt;/tr&gt;
          &lt;/table&gt;
      &lt;/div&gt;
      &lt;br /&gt;
      &lt;div align="right"&gt;
          &lt;input type="submit" name="btnOK" value="Ok" /&gt;
          &lt;input type="reset" name="btnCancel" value="Cancel" onclick="Close()" /&gt;
      &lt;/div&gt;
      &lt;/form&gt;
  &lt;/body&gt;
  &lt;/html&gt;
  </code></pre>
  
  <p>I am trying to focus on first input in the dialog, which is not happening. the actual focused element is the close button (you can verify this by pressing enter, which closes the dialog)</p>
  
  <p>Please note, content of the dialog is inside and <code>iframe</code>. I cannot combine the content of dialog by inserting html directly to div tag. both pages are active aspx pages and cannot be simply combined. Actual dialog contents are more complex than a few input boxes and can be combination of <code>datebox</code>, <code>dropdown</code>, <code>textarea</code>, <code>multiselect</code>, ...</p>
  
  <p>Please note, <code>setTimeout</code> didn't work either because dialog waits for the page to return control to parent before opening it</p>
  
  <p><strong>Question</strong>
  How can I focus move focus to first component in dialog box (in this case password input)</p>