Javascript single quot eissue

Hello,

I have this function How do I get single quotes around the value.
          fixedFilterPart = 'owner_text='+document.all.ownerType.value;

Whatever value I get document.all.ownerType.value should be enclosed in single quotes

psl help


////////////////////////////////////////////////
function FilterOwner()
////////////////////////////////////////////////
{
      with (document.all.documentGrid)
      {
          alert(document.all.ownerType.value)
          if(document.all.ownerType.value=="")
          {
          fixedFilterPart=""
          }
          else
          {
          fixedFilterPart = 'owner_text='+document.all.ownerType.value;
          }
            
            loadData()
      }
}
sureshrainaAsked:
Who is Participating?
 
Harisha M GConnect With a Mentor Commented:
fixedFilterPart = 'owner_text=\''+document.all.ownerType.value+'\'';
0
 
0h4crying0utloudCommented:
this should work:

fixedFilterPart = "owner_text="+"'" + document.all.ownerType.value+ "'";
0
 
netsmithcentralCommented:
Use \ before the ' to escape the character.

fixedFilterPart='owner_text=\''+document.all.ownerType.value+'\'';
0
 
Harisha M GCommented:
suresh raina (?),

If you know C, then you will know about escape characters. In C, you'll use \' for single quotes and \" for double quotes.

In Javascript too, you need the same. But here, you don't need to escape single quote inside double quotes or double quote inside single quotes. What you need to escape is.. single quote inside single quotes and double quote inside double quotes.

So,
"'" is same as '\''
and
'"' is same as "\""



0
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.