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

Coldfusion 2018 compiler

New Here ,
Feb 04, 2021 Feb 04, 2021

Copy link to clipboard

Copied

Within a cfm, I have a script section and the pre-compiler is throwing this error - it is not recognixing that $("#selectname") is valid invalid token at the second ". Any ideas on how to go around the problem? 

defaultvqcg5vyrikvh_0-1612473063544.png

defaultvqcg5vyrikvh_2-1612473117899.png

 

 

 

Views

170

Translate

Translate

Report

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

Community Expert , Feb 05, 2021 Feb 05, 2021

If the Javascript is not part of CF code, then use single #.

If the Javascript is part of CF code (for example, within cfoutput tags), then use ## instead of #.

 

testPage1.cfm

<!--- 
If Javascript is not part of CF code, then use single # 
--->
<script type="text/javascript" language="Javascript">
$( function(){
 
  $("#selectname").autocomplete({
    source: arrNames,
    select: function(event, ui) {
      $("#selectedname").val(ui.item.value);
    },
    
  });
  
});
</script>


testPage2.
...

Votes

Translate

Translate
Community Expert ,
Feb 04, 2021 Feb 04, 2021

Copy link to clipboard

Copied

Use ## where you are using #.

 

While your code is all fine js code, if this is in a cfm page, cf sees the # as the start of a variable or expression. That's where it would complain.

 

Using two #'s would "escape" the use of a single one.

 

Let us know of that solves things. 


/Charlie (troubleshooter, carehart.org)

Votes

Translate

Translate

Report

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
Community Expert ,
Feb 05, 2021 Feb 05, 2021

Copy link to clipboard

Copied

If the Javascript is not part of CF code, then use single #.

If the Javascript is part of CF code (for example, within cfoutput tags), then use ## instead of #.

 

testPage1.cfm

<!--- 
If Javascript is not part of CF code, then use single # 
--->
<script type="text/javascript" language="Javascript">
$( function(){
 
  $("#selectname").autocomplete({
    source: arrNames,
    select: function(event, ui) {
      $("#selectedname").val(ui.item.value);
    },
    
  });
  
});
</script>


testPage2.cfm

<!--- 
If Javascript is part of CF code (for example, 
within cfoutput tags), then use ## 
--->
<cfoutput>
<script type="text/javascript" language="Javascript">
$( function(){
 
  $("##selectname").autocomplete({
    source: arrNames,
    select: function(event, ui) {
      $("##selectedname").val(ui.item.value);
    },
    
  });
  
});
</script>
</cfoutput>

 

 

 

 

Votes

Translate

Translate

Report

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
New Here ,
Feb 05, 2021 Feb 05, 2021

Copy link to clipboard

Copied

LATEST

Thanks for the quick replies - have yourselves a great day.

Dave

Votes

Translate

Translate

Report

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
Documentation