Link to home
Start Free TrialLog in
Avatar of sureshraina
sureshraina

asked on

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()
      }
}
Avatar of 0h4crying0utloud
0h4crying0utloud

this should work:

fixedFilterPart = "owner_text="+"'" + document.all.ownerType.value+ "'";
ASKER CERTIFIED SOLUTION
Avatar of Harisha M G
Harisha M G
Flag of India image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Use \ before the ' to escape the character.

fixedFilterPart='owner_text=\''+document.all.ownerType.value+'\'';
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 "\""