This is a migrated thread and some comments may be shown as answers.

how to pass special characters in javascript method

2 Answers 768 Views
General Discussions
This is a migrated thread and some comments may be shown as answers.
bharat veer
Top achievements
Rank 1
bharat veer asked on 06 Jun 2011, 07:38 PM
hi,
i have a  java script method for showing the alert message. its work fine.
 function openAlert(type, msg, method, width, height)
    {                
                    switch (type) {
                        case "Info":
                            var oWnd = radalert(msg, width, height, ' ');
                            var popupElement = oWnd.get_popupElement();
                            popupElement.className = popupElement.className + " infoIcon";
                            break;               
                    }
                }
but when i called this way with some special characters
openalert('Info','Please enter proper delimiters i.e(' '   ','  ' | '  '-' ) with start and end characters, ' ', 400,300);
(' '   ','  ' | '  '-' ) space,coma, | and - characters i am trying to pass this function but not working.
please tell how can the special characters be passed to the java script method so that they can be shown in message.

2 Answers, 1 is accepted

Sort by
0
Accepted
Gimmik
Top achievements
Rank 1
answered on 06 Jun 2011, 08:50 PM
Hello Bharat,

You can escape special characters in JavaScript by using the backslash ( \ ) character. So if you want to include a quote in a string (without terminating your string) you can do something like this. "He said \"Hello World\" to me." Here is a link with more more information.

http://www.w3schools.com/js/js_special_characters.asp

Hope this helps,
-Gimmik
0
bharat veer
Top achievements
Rank 1
answered on 07 Jun 2011, 01:29 PM
thanks sir
Raja
Top achievements
Rank 1
commented on 03 Feb 2025, 12:41 PM

To pass special characters in JavaScript strings, escape them properly. For instance:

javascript
openAlert('Info', "Please enter proper delimiters i.e. (' ', ',' , '|' , '-')", ' ', 400, 300);

Or, escape single quotes like this:

javascript
openAlert('Info', 'Please enter proper delimiters i.e. (\' \', \',\' , \'|\' , \'-\')', ' ', 400, 300);

This ensures the characters display correctly in the alert.

Also if, If you’re looking to kickstart your career in software testing, our training program is the ideal choice. With a curriculum designed to meet industry standards, our Software Testing Classes in Pune  focus on practical learning, hands-on projects, and real-world tools. Whether you’re a beginner or a professional aiming to upskill, this program provides the perfect blend of theoretical knowledge and practical experience. For those who prefer flexibility, we also offer online training options. Our Testing Course in Pune is tailored to help you build a strong foundation, enhance your expertise, and open the door to exciting career opportunities. Don’t wait—join us today and take the first step toward a successful career in software testing!

Tags
General Discussions
Asked by
bharat veer
Top achievements
Rank 1
Answers by
Gimmik
Top achievements
Rank 1
bharat veer
Top achievements
Rank 1
Share this question
or