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 strongm on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Find " and replace with ' in form Entry

Status
Not open for further replies.

Joules

MIS
Apr 25, 2001
28
US
I creating a form that sends the results in an email. I have found that if the user imputs " the rest of the entry gets dropped off. I thought that if I could go through the entry and replace all double quotes with single quotes, it would work right. is there a find/replace type of function in javascript?

Thanks :-{}

 
will this work?

function search(element){
var newStr =element.value;
for(var i=0;i<element.value.length;i++){
newStr = newStr.replace('&quot;','\'');
}

}

Maybe replace \' with \&quot; and see if it works.
b[sup]2[/sup] - benbiddington@surf4nix.com
 
I keep getting an invalid character error that looks like it is pointing to the 2nd line. I can't tell what it would be. I'm tired so I'm giving up for the day...I'll try again tomorrow.

|-I

 
Darn, I'm sorry, I had it plugged in to a form still - try this one which takes a string as an argument:


function search(string){
var newStr = string;
for(var i=0;i<string.length;i++){
newStr = newStr.replace('&quot;','\&quot;');
}
return newStr;

}


The reason it loops is so it finds all of them in the string, otherwise it stops after finding the first one!

e.g. - var nameInQuotes = search(&quot;Ben&quot;);

nameInQuotes now is &quot;Ben&quot;.


b[sup]2[/sup] - benbiddington@surf4nix.com
 
Just to close off this thread, I decided to use VBscript...

function ReplaceItem(str1)
ReplaceItem = Replace(str1,&quot;&quot;&quot;&quot;,&quot;''&quot;)
End Function

As easy as that! I replaced with 2 single quotes so that it looks like double quotes but will still email.

X-)
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top