Solved

Javascript single quot eissue

Posted on 2006-06-28
4
216 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 500 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

Free Tool: Path Explorer

An intuitive utility to help find the CSS path to UI elements on a webpage. These paths are used frequently in a variety of front-end development and QA automation tasks.

One of a set of tools we're offering as a way of saying thank you for being a part of the community.

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
key press alert 2 32
Google Analytics setup 5 50
forgetful about js objects 8 46
return false must be hit after calling certain command 10 31
This article shows how to create and access 2-dimensional arrays in JavaScript.  It includes a tutorial in case you are just trying to "get your head wrapped around" the concept and we'll also look at some useful tips for more advanced programmers. …
Today I would like to talk about localizing (Internationalization) JavaScript applications. Introduction When creating an application that is going to be used by many people around the globe, it is important to remember that not everyone speak…
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…

792 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