problem when passing a value with single quote

I have the following javascript in  When NameStr has a single quote like, then it stop working.  How to fix ?  Thanks.

  jscript = "<script>window.opener.baseform.well_name.value='" & NameStr & "';opener.document.forms(0).submit(); opener.focus(); self.close();</script>"

Who is Participating?
ZvonkoSystems architectCommented:
Better this:

 jscript = "<script>theForm=window.opener.document.baseform;theForm.well_name.value='" & Replace(NameStr,"'","\'") & "';theForm.submit(); opener.focus(); self.close();</script>"

Escape the quotes with a backslash?

I'm not familiar with, but a js example...

var myStr = 'string\'s with quote\'s';

ZvonkoSystems architectCommented:
Check this:

 jscript = "<script>window.opener.baseform.well_name.value='" & Replace(NameStr,"'","\'") & "';opener.document.forms(0).submit(); opener.focus(); self.close();</script>"

Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

All Courses

From novice to tech pro — start learning today.