title: Passing PHP Result to JS via jQuery .get
body: <p>I have several instances where a form is brought into the page in an overlay via ajax. On these forms I have a "math validation" question (I know not the most secure). I am using the following to generate the problem:</p>
  
  <pre><code>&lt;?php
      $randomNum = rand(0,9);
      $randomNum2 = rand(0,9);
      $randomNumTotal = $randomNum + $randomNum2;
  ?&gt;
  </code></pre>
  
  <p>the random number is displayed in a text box like so:</p>
  
  <pre><code>&lt;input type="text" name="someName" value="&lt;?= $randomNum ?&gt; + &lt;?= $randomNum2 ?&gt;" readonly&gt;
  </code></pre>
  
  <p>and validated:</p>
  
  <pre><code>...
  SomeName: {
      required: true,
      equal: &lt;?php echo $randomNumTotal; ?&gt;   
   }
      ...
  </code></pre>
  
  <p>This works fine when the form is on the page, hidden and then displayed with a .click function. I would like to store the files remotely and display them via AJAX. No problem doing that, the problem is when I do this, the numbers generated don't match the value. I've tried putting the PHP $randomeNumTotal function on both the form itself that is brought in via AJAX and on the parent page. Neither works. </p>
  
  <p><b>So my question is this:</b> Can I store the PHP function in a remote file "random.php", then pass the value to it via .get? If so, how do I make "SomeName" value equal the value from the file?</p>
  
  <pre><code>&lt;script&gt;
    $.get( 'random.php', function ( data ) {
      $("SomeName").val('random.php')?//I know this isn't right
   });
  &lt;/script&gt;
  </code></pre>
  
  <p>Thanks!</p>