var.replace is not a function
<p>I'm using the below code to try to trim the string in Javascript but am getting the error mentioned in the title..</p>

<pre><code>function trim(str) {
    return str.replace(/^\s+|\s+$/g,'');
}
</code></pre>

<p>Any idea why?</p>

<p>Thanks!</p>

<p><strong>Edit:</strong></p>

<p>I fixed the problem.... sorry I should have put the code on how I was calling it too.... realized I accidentally was passing the object of the form field itself rather than its value.</p>

<p>Thanks for your responses anyway. :)</p>
