Replace Function

Results 1 to 3 of 3

Thread: Replace Function

  1. #1
    Linda Guest

    Default Replace Function

    The below function is what I am using to replace a single quote when user enters in a text field. I have been told that instead of replacing with` character I should replace with double quotes. When I do this all sorts of problems occur. I have posted this question before but I keep getting new functions suggested to me. While I appreciate the suggestions, this causes further confusion because I have to amend existing code and all sorts of other errors end up occuring. Is there anyway to change my existing code or should I just leave it alone?<BR><BR>I have also tried replacing &#039 with follwing code which give me an error. add="&#039&#039"<BR><BR>My code is as follows:<BR>function replaceCharsA1(entry) {<BR>out = "&#039"; // replace this<BR>add = "`"; // with this<BR>temp = "" + entry; // temporary holder<BR><BR>while (temp.indexOf(out)&#062;-1) {<BR>pos= temp.indexOf(out);<BR>temp = "" + (temp.substring(0, pos) + add + <BR>temp.substring((pos + out.length), temp.length));<BR>}<BR>document.forms[0].Address1.value = temp;<BR>}<BR><BR><BR>

  2. #2
    Join Date
    Dec 1969

    Default RE: Replace Function

    in javascript, all single quotes must be escaped<BR><BR>"&#039";<BR>"&#039&#039";<BR><BR>th at should work. you could of course use regular expression and javascript&#039s replace function<BR><BR>string.replace(/&#039/g,"&#039&#039");<BR><BR>where string is the reference to the string you&#039re fixing<BR>(i just tested it, it works)<BR><BR>Jason<BR><BR>function sqlfix(str) {<BR>return str.replace(/&#039/g,"&#039&#039");<BR>}

  3. #3
    Linda Guest

    Default RE: Replace Function

    Thanks I&#039ll try it and see if it works

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts