try<input type="text" id="filepath" value="c:\windows\system">
<script language="javascript">
str = filepath.value;
alert(str);
str = str.replace(/\\/g,"\\\\");
alert(str);
</script>