title: JQuery fails when part of PHP include but not if injected by PHP
body: <p>All right folks I have a problem with some jQuery error handling code I have written.  The issue is, if I write the jQuery code so that PHP injects it into the page using echo statements the code works just fine.  However if I just enter the jQuery code after the end of the php statements and let it be included as if it were just normal html it fails to work.  I suspect that there is some sort of issue with the elements not being available in the DOM when the jQuery actually makes it back to the browser but I'm not sure how this could be the case.</p>
  
  <p>As for the code here are the examples.</p>
  
  <p>This is how the code is written if it is included after the ending ?> tag of the php in the include file.</p>
  
  <pre><code>&lt;script&gt;
  
      $("#adminuserlist select[name=userlist]").change(function(){ 
              if($("#adminuserlist select[name=userlist]").val() == \'\'){
                  $("#noadminuser").css("visibility", "visible"); 
                  $("#noadminuser").dialog({ 
                      modal:true, 
                      show: { 
                          effect: "fade", 
                          duration: 300 
                      }, 
                      hide: { 
                          effect: "fade", 
                          duration: 300 
                      } 
                  }); 
              } 
              else{ 
                  $("#adminuserlist").submit(); 
              }
          }
      );
  
  &lt;/script&gt;
  </code></pre>
  
  <p>This is how the code looks when I inject it with PHP.  It works if I do it this way, but it is, in my mind a bit of an organizational nightmare.</p>
  
  <pre><code>&lt;?php echo '&lt;script&gt;';
  
      echo '$("#adminuserlist select[name=userlist]").change(function(){ if($("#adminuserlist select[name=userlist]").val() == \'\'){ $("#noadminuser").css("visibility", "visible"); $("#noadminuser").dialog({ modal:true, show: { effect: "fade", duration: 300 }, hide: { effect: "fade", duration: 300 } }); } else{ $("#adminuserlist").submit(); }});';
  
  echo '&lt;/script&gt;'; ?&gt;
  </code></pre>
  
  <p>When I examine the result source in the browser from both of these configurations they seem identical beyond the spacing.  If this is some sort of issue with the elements not existing in the DOM when the jQuery is loaded I would love to hear a way to fix it.  I have tried the delegate binding method using on.  I have tried encapsulating the code in a $(document).ready statement, and a number of other methods but it seems to ignore all of my efforts when I do not inject the jQuery code using PHP.</p>
  
  <p>What baffles me the most is I have a similar page that uses a  and the .click method instead of a  with the .change method that works perfectly when the jQuery code is included as straight HTML after the PHP code.  I'm stumped so any input would be great.</p>
  
  <p>Thanks in advance.</p>