The javascript code below will trim the leading and trailing spaces from a string.
<script language="javascript">
function trim(str)
{
while(''+str.charAt(0)==' ')
str=str.substring(1,str.length);
while(''+str.charAt(str.length-1)==' ')
str=str.substring(0,str.length-1);
return str;
}
</script>