User Id :    Password :      New Member   Forgot Password  
 
Insert Special Characters Using JavaScript
Description The backslash (\) is used to insert apostrophes, new lines, quotes, and other special characters into a text string.   No. of Views     1658
  Rating     3
Author Najmul Hoda   Posted On     01 Feb 2010
Tags Java Script    

Sample Code   Download Code

Introduction

Before explaining the article, I would like to thank all readers who read my article and voted for it.
Your appreciation for my article gives me strength to write more good articles. Hope in future I will get your valuable comments and suggestions.
Now I won't waste your time and come back to the topic. I have written this article on ‘Insert Special Characters’. The backslash (\) is used to insert apostrophes, new lines, quotes, and other special characters into a text string.


Look at the following JavaScript code:

var txt="We are from “DotNetLogix" technical team;
document.write(txt);

In JavaScript, a string is started and stopped with either single or double quotes. This means that the string above will be chopped to: We are the so-called
To solve this problem, you must place a backslash (\) before each double quote in "Viking". This turns each double quote into a string literal:
 var txt="We are from\"DotNetLogix\" technical team.";
 document.write(txt);
JavaScript will now output the proper text string: We are the so-called "Vikings" from the north.
Here is another example:
 document.write ("You \& Us can improve our skills!");
The example above will produce the following output:
"You & Us can improve our skills!


Thanks.....

About Author

About Author He is a team lead, having 8+ years of experience. He loves writing technical article for .Net developers. Najmul Hoda
No Photo
 
Country United States
Company BirlaSoft
Home Page http://www.magixchat.com

Rate this article

Rating options from poor, fair, good, very good to excelent.  
 

Comments

 
 
Posted By Annonymous on 12 Aug 2011 at 10:42 AM
 
What if I want to pass characters like "-" , "?" . What needs to be done in such cases ?
 
 
   
Write your comment here.
Comment
Verification Code