Exit
  • Global community
    • Language:
      • Deutsch
      • English
      • Español
      • Français
      • Português
  • 日本語コミュニティ
  • 한국 커뮤니티
0

Special Character Handling

Guest
Nov 25, 2011 Nov 25, 2011

Hi,

I'm using the ColdFusion.navigate in JavaScript to call Method in CFC.

ColdFusion.navigate('cfc/data_control.cfc?method=insertCompanyName&company_id='+document.getElementById('company_id_'+i).value+'&company_name='+document.getElementById('company_name_'+i).innerText,'addMessage',loadCompanyList);

However, I find that when I input the name "Testing & Checking" in the field, it will only show me the word "Testing ". I think this is because of the character "&". "&" is used to divide different parameter. Since some companies have the character "&", I want to find some method to retrieve the character "&" correctly.

Is there any method on handling "&" correctly?

1.3K
Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines

correct answers 1 Correct answer

LEGEND , Nov 28, 2011 Nov 28, 2011

I know the above answer has been marked as "correct", but I'm afraid it's not the best way of going about things, nor is it complete.

There are more characters the user could potentially enter which will cause problems here than just ampersand.  Fortunately this possibility was predicted by the JavaScript bods, so there's a function to deal with it: encodeURIComponent():

http://www.w3schools.com/jsref/jsref_encodeuricomponent.asp

That is what should be being used in these situations.

--

Adam

Translate
Advocate ,
Nov 27, 2011 Nov 27, 2011

You'll need to use a JavaScript string replace() method (or a similar equivalent) in order to do that since your code is being executed client side rather than server side.  Replace it with its corresponding URL encoded value (%26)

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
LEGEND ,
Nov 28, 2011 Nov 28, 2011
LATEST

I know the above answer has been marked as "correct", but I'm afraid it's not the best way of going about things, nor is it complete.

There are more characters the user could potentially enter which will cause problems here than just ampersand.  Fortunately this possibility was predicted by the JavaScript bods, so there's a function to deal with it: encodeURIComponent():

http://www.w3schools.com/jsref/jsref_encodeuricomponent.asp

That is what should be being used in these situations.

--

Adam

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Resources