title: Why replace backslash code doesn't work in JS?
body: <p>My code in JSP file looks like this : </p>
  
  <pre><code>&lt;s:form namespace="/user" action="list" method="POST" id="filterListForm" theme="simple"
          onsubmit="document.getElementById('filterSearchText').value=document.getElementById('filterSearchText').value.replace(/\\/g,'')"&gt;
  </code></pre>
  
  <p>It won't replace the backslash char. I've tried the following, none of them work :</p>
  
  <pre><code>replace('/\\/g','')
  replace(/\\\\/g,'')
  replace(\/\\\/g,'')
  </code></pre>
  
  <p>But if I change it to the following, it works :</p>
  
  <pre><code>&lt;s:form namespace="/user" action="list" method="POST" id="filterListForm" theme="simple"
          onsubmit="replaceBackslash()"&gt;
  
  &lt;script type="text/javascript"&gt;
    function replaceBackslash() { document.getElementById('filterSearchText').value=document.getElementById('filterSearchText').value.replace(/\\/g,''); }
  &lt;/script&gt;
  </code></pre>
  
  <p>Why ? Is there a way to make it work in the first case ?</p>