title: How to Pass PHP String Variable To JS From an Onclick Event
body: <p>This might have a simple answer, however I cannot figure out the correct syntax.  I have the following onclick event echoed on a php page: </p>
  
  <pre><code>$ratelink = text string...
  echo '&lt;div&gt;&lt;span id="anything" onclick="updatePos('.$ratelink.')"&gt;Save&lt;/div&gt;';
  </code></pre>
  
  <p>On my JS page, I have the function:</p>
  
  <pre><code>function updatePos(ratelink)
  {
    alert(ratelink); 
  }
  </code></pre>
  
  <p>My problem is that when $ratelink is a number, the variable will pass with no problems.  However, when $ratelink is a text string, like in the above example, nothing gets passed and the alert doesn't execute.</p>
  
  <p>I think the following ('.$ratelink.') needs to be in a different syntax to pass text, but I don't know the exact format.</p>