Go Premium for a chance to win a PS4. Enter to Win

x
?
Solved

Javascript single quot eissue

Posted on 2006-06-28
4
Medium Priority
?
226 Views
Last Modified: 2008-03-03
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()
      }
}
0
Comment
Question by:sureshraina
  • 2
4 Comments
 
LVL 10

Expert Comment

by:0h4crying0utloud
ID: 17005215
this should work:

fixedFilterPart = "owner_text="+"'" + document.all.ownerType.value+ "'";
0
 
LVL 37

Accepted Solution

by:
Harisha M G earned 2000 total points
ID: 17005216
fixedFilterPart = 'owner_text=\''+document.all.ownerType.value+'\'';
0
 
LVL 12

Expert Comment

by:netsmithcentral
ID: 17005223
Use \ before the ' to escape the character.

fixedFilterPart='owner_text=\''+document.all.ownerType.value+'\'';
0
 
LVL 37

Expert Comment

by:Harisha M G
ID: 17005250
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

Featured Post

[Webinar] Cloud Security

In this webinar you will learn:

-Why existing firewall and DMZ architectures are not suited for securing cloud applications
-How to make your enterprise “Cloud Ready”, and fix your aging DMZ architecture
-How to transform your enterprise and become a Cloud Enabler

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

This article discusses the difference between strict equality operator and equality operator in JavaScript. The Need: Because JavaScript performs an implicit type conversion when performing comparisons, we have to take this into account when wri…
This article discusses how to create an extensible mechanism for linked drop downs.
The viewer will learn the basics of jQuery, including how to invoke it on a web page. Reference your jQuery libraries: (CODE) Include your new external js/jQuery file: (CODE) Write your first lines of code to setup your site for jQuery.: (CODE)
The viewer will learn the basics of jQuery including how to code hide show and toggles. Reference your jQuery libraries: (CODE) Include your new external js/jQuery file: (CODE) Write your first lines of code to setup your site for jQuery…
Suggested Courses

916 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question