Replace apostrophe still a PROBLEM

Results 1 to 5 of 5

Thread: Replace apostrophe still a PROBLEM

  1. #1
    Linda Guest

    Default Replace apostrophe still a PROBLEM

    I am still having problems replacing a single apostrophe in a string. The coe I am using is below.<BR>When I use "&#039&#039", my computer freezes up!! <BR>If use "&#039&#039", then I get a syntax error. I JUST DON&#039T KNOW WHAT I AM DOING WRONG. I have tried to follow all advice given but I can&#039t seem to get it right. Please help. <BR><BR>function replaceCharsFN(entry) {<BR>out = "&#039"; // replace this<BR>add = "&#039&#039"; // 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].FName.value = temp;<BR>}<BR><BR><BR>

  2. #2
    KPW Guest

    Default RE: Replace apostrophe still a PROBLEM

    Hi,<BR><BR>What is the context under which you are replacing the single quote? Is it a form value that you want to change before submitting it to a form handler?<BR><BR>If we know the context, perhaps we could figure out a different way of tackling this problem.

  3. #3
    Linda Guest

    Default RE: Replace apostrophe still a PROBLEM

    I have a form that I want to validate the text boxes before submitting. If the user enters a single quote anywhere in the text area, I want to replace it with a double quote before submitting. This text value is being submitted (inserted into)to a database.<BR><BR>I have figured out how to get the function to work if I replace a single quote with a `. This works fine, it&#039s once I start trying to replace a &#039 with a &#039&#039 that the problem arises. Hope this clarifies what I am trying to do.

  4. #4
    KPW Guest

    Default RE: Replace apostrophe still a PROBLEM

    Instead of worrying about it client-side before it&#039s submitted, why don&#039t you worry about them server-side in your form handler? That way, in VBScript, you could do<BR><BR>&#060;%<BR>Dim sMyTextBox<BR><BR>sMyTextBox = Request.Form("txtMyTextBox")<BR>sMyTextBox = Replace(sMyTextBox,"&#039","&#039&#039")<BR><BR>%& #062;<BR><BR>(A fairly crude example, but I think you get the idea.)<BR><BR>Just do this with each of your text boxes, then insert the values into your DB.<BR><BR>Does this help?

  5. #5
    Linda Guest

    Default HELP!!!!!!

    I am sooo fed up. I still get that stupid syntax error.<BR>The code is not changing the single quote to double quotes. I used the example you gave and substituted appropriate names, but it is not replacing the single quote.<BR><BR>I give up!!!!!!! The function works for everyone else but me, why????? This is sooo simple yet it is becoming a major pain for me.

Posting Permissions

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