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

[Solved] how to pass special characters in javascript method

3 Answers 1015 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.

3 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
0
Robbert
Top achievements
Rank 1
answered on 19 Nov 2026, 01:36 PM

Hi Bharat,

The issue happens because the single quotes inside your message string are prematurely closing the string parameter, and JavaScript is also case-sensitive (openAlert vs openalert).

You can fix this in two clean ways:

1. Use template literals (backticks `) This is the easiest approach in modern JavaScript since you don't have to escape single or double quotes inside the text:

2. Escape the inner quotes with a backslash (\) or wrap the string in double quotes (")

Also, when building custom validation alerts and interactive popups for complex web applications, small details in how error messages are formatted and displayed make a big difference for usability. If your team is ever looking to refine user flows or overhaul complex interfaces, checking out professional can be really helpful for streamlining error handling and overall user experience.

Hope this solves your issue!

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