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.val ue should be enclosed in single quotes
psl help
////////////////////////// ////////// ////////// //
function FilterOwner()
////////////////////////// ////////// ////////// //
{
with (document.all.documentGrid )
{
alert(document.all.ownerTy pe.value)
if(document.all.ownerType. value=="")
{
fixedFilterPart=""
}
else
{
fixedFilterPart = 'owner_text='+document.all .ownerType .value;
}
loadData()
}
}
I have this function How do I get single quotes around the value.
fixedFilterPart = 'owner_text='+document.all
Whatever value I get document.all.ownerType.val
psl help
//////////////////////////
function FilterOwner()
//////////////////////////
{
with (document.all.documentGrid
{
alert(document.all.ownerTy
if(document.all.ownerType.
{
fixedFilterPart=""
}
else
{
fixedFilterPart = 'owner_text='+document.all
}
loadData()
}
}
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Use \ before the ' to escape the character.
fixedFilterPart='owner_tex t=\''+docu ment.all.o wnerType.v alue+'\'';
fixedFilterPart='owner_tex
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 "\""
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 "\""
fixedFilterPart = "owner_text="+"'" + document.all.ownerType.val