title: how to escape html / special strings in javascript
body: <p>I have a php / javascript scrip which needs to print some text. unfortunately  it seems that the js breaks down if the string has special characters such <pre>'</pre></p>
  
  <p>Below is a snippet from the script. $messageContent and $subject are the strings with html tags. (actually  "'" characters) .
  <pre></p>
  
  <code>echo '
  &lt;script language="javascript"&gt;
  function SelectRedirect(){
  switch(document.getElementById(\'s1\').value)
  {
  ';
  
  echo '
  case "?vrj_name='.$vrj_name.'":
  window.location="?vrj_name='.$vrj_name.'&amp;messageContent='.$messageContent_vrj.'&amp;from_email='.$from_email.'&amp;email='.$email.'&amp;subject='.$subject.'";
  break;
  ';
  }
  </code></pre>
  
  <p></p>
  
  <p>I added a function in php to replace "'" with "\'" and it works (the js executes successfully ) but I can't get ride of them when I display them in the webpage .</p>