Howdy, Stranger!

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

Categories

Welcome to the new platform of Programmer's Heaven! We apologize for the inconvenience caused, if you visited us from a broken link of the previous version. The main reason to move to a new platform is to provide more effective and collaborative experience to you all. Please feel free to experience the new platform and use its exciting features. Contact us for any issue that you need to get clarified. We are more than happy to help you.

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.