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

pushing text from popup to opener

Status
Not open for further replies.

ks1392

Programmer
Dec 7, 2001
63
0
0
US
Hi, I'm relatively new to JS. I have a function that pops up a window, then from the popup a user will select some text. The text will then be placed in a <textarea> tag in the opener as the popup closes. The (very simple) function is:

function put_back(form,field,text) {
opener.document.forms[form].elements[field].value = text;
self.close();
}

The function is called via an anchor tag. It works great until the text I'm sending back to the opener has any single quotes in it. I imagine I have to escape these characters. The text is generated on the fly by database queries, so I suppose I need a function to do this.

Am I going in the right direction? If so, does anyone know of a function that will parse a a string and escape the appropriate characters? If not, what should I be doing?

Thanks in advance,
Kerr
 
How are you writing the links from the database? Is it with ASP? If so, you could use the REPLACE function.
Code:
<a href="javascript:put_back('formName','fieldName','<%=Replace(rs.Fields("dbField")&"","'","\'")%>')">

The &"" in the replace function is to keep it from erroring if the field is null.

Adam
while(ignorance){perpetuate(violence,fear,hatred);life=life-1};
 
I'm using ColdFusion on the server side. I hadn't thought to do this using CF. I will work it from that angle with CF's regex functions.

I did try using the JS 'escape' function and while it hex encoded all the spaces, etc. it still failed when I handed it a single quote.

Hey your sig is an infinite loop! :)
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top