How to replace ' with ' in a textbox - Programmers Heaven

Howdy, Stranger!

It looks like you're new here. If you want to get involved, click one of these buttons!

Categories

How to replace ' with ' in a textbox

snobord15snobord15 Posts: 4Member
Hi.

I need to use escape sequences for the ' and characters. To do this, I must parse the value in a textfield, searching for the said characters, and prefix them with a forward slash, .

I have used regular expressions and can locate the characters, and I can use the replace method and replace them with any string EXCEPT the character.

Below is the validateText method I created:

function validateText(elemName, str) {
var regExp = /'/g;
str = str.replace(regExp, "'");
eval("document.mainupdate."+elemName+".value=""+str+""");
}

Thank you for any help provided. I can also you Java if need be.

- Mike

Comments

  • StannyBoyStannyBoy Posts: 115Member
    It's quite easy, just change your line to
    str = str.replace(regExp, "\'");

    SB


    : Hi.
    :
    : I need to use escape sequences for the ' and characters. To do this, I must parse the value in a textfield, searching for the said characters, and prefix them with a forward slash, .
    :
    : I have used regular expressions and can locate the characters, and I can use the replace method and replace them with any string EXCEPT the character.
    :
    : Below is the validateText method I created:
    :
    : function validateText(elemName, str) {
    : var regExp = /'/g;
    : str = str.replace(regExp, "'");
    : eval("document.mainupdate."+elemName+".value=""+str+""");
    : }
    :
    : Thank you for any help provided. I can also you Java if need be.
    :
    : - Mike
    :
    :

Sign In or Register to comment.