function readOnly(count){ }
Starting November 20, the site will be set to read-only. On December 4, 2023,
forum discussions will move to the Trailblazer Community.
+ Start a Discussion
jeremyyjeremyy 

VF mangling my JavaScript

I'm having an issue with what I believe is VF trying to interploate JavaScript. For example, given this JavaScript embedded in a VF page:

 

 

html += "<input type='checkbox' id='plVal" + val + "' value='" 
+ field.picklistValues[val]+ "'/> " + field.picklistValues[val] + "<br/>";

 This is output by VF:

 

html += "<input id="plVal&quot; + val + &quot;" type="checkbox" value="&quot; 
+ field.picklistValues[val]+ &quot;"/> " + field.picklistValues[val] + "<br/>";

notice that VF has apparently identified the <input> which is inside a JS string. It swapped the order of the id and type attributes, and screwed some stuff up. 

 

How can I prevent this? I tried the old trick surrrounding the JS code w/ html comments (<!-- -->), but VF outputs nothing but asterisks for the JS code. 

 

Any idea how to prevent this, besides moving JS to an external file?

 

 

Best Answer chosen by Admin (Salesforce Developers) 
jwetzlerjwetzler

Which API version is your page using?  We made a change to the VF compiler a few releases ago that should fix most if not all of these javascript issues, but it was pretty invasive and had to be versioned.  If your page is using version 20.0 or higher I would expect this to go away.

All Answers

jwetzlerjwetzler

Which API version is your page using?  We made a change to the VF compiler a few releases ago that should fix most if not all of these javascript issues, but it was pretty invasive and had to be versioned.  If your page is using version 20.0 or higher I would expect this to go away.

This was selected as the best answer
fractasticalfractastical

I'll bet you can get around this simply by breaking up the "input" into two different strings. (e.g. "in" + "put").

jeremyyjeremyy

Jill,

 

I bumped it from v19 to v21 and it solved the problem. Thanks for the tip!

 

Jeremy