Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations wOOdy-Soft on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Adding backslashes before quotes

Status
Not open for further replies.

Quasibobo

Programmer
Oct 11, 2001
168
NL
Help please,

I am having difficulties with a function of mine working properly. It is a popup which uses the values of some textarea's to build a Preview of the page. But since in the textarea's people can use quotes it sometimes messes up the code for the popup.

Does anybody know a function, or has built one, which searches for quotes or forwardslashes and puts backslashes before it so it doesn't mess up the popup function?

Suggestions welcome

Don't eat yellow snow!
 
If you don't mind changing the quotes a user may have entered, then some variation of the following could work for you:

Code:
 var newText = tField.value.replace(/"/g,"`");
 newText = newText.replace(/'/g,"`");

Call a function with this (or a variation of this) in it before the popup is called. Send the newText as the contents.

'hope that helps.

--Dave
 
This function will return a "safe" version of your input text field.

Code:
function makeSafe(myVar)
{
	return(myVar.replace(/\\/g,"\\").replace(/\'/g,"\'").replace(/\"/g,"\""));
}

Cheers,
Jeff
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top