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
JasonGablerJasonGabler 

Did I find a bug? Visualforce compiler edited my Javascript, breaking syntax

 

 

Here's my javascript, pasted from my Force.com IDE.  Pay particular attention to the bold lines.

 

 

<script type="text/javascript">
  $(document).ready(function() {
  	$('#submit').attr('value', '');
  	$('#gate-form').submit(function() {
	  	var pass = true;
	  	for(var i=1; i<7; i++) {
	  		if (!$('#q'+i).attr('checked')) {
	  			pass = false;
	  		}
	  	}
	 		if (pass) {
	 			location.replace = '/somepage';
			} else {
				alert('fail :(');
			}
			return false;
		});
	});
</script>

 

 

Here it is, pasted from my browser's page source.  We can see what the VF compiler did.  If its not obvious at first, notice that my location.href got chopped up and the "replace = '/somepage'"  was inserted into the preceding for loop, breaking the syntax, breaking the JS compiling in my browser.

 

 

 

<script type="text/javascript">
  $(document).ready(function() {
   $('#submit').attr('value', '');
   $('#gate-form').submit(function() {
    var pass = true;
    for(var i=1; i<7 replace="/RFQ_Page_1" ; i++) {
     if (!$('#q'+i).attr('checked')) {
      pass = false;
     }
    }
    if (pass) {
     location.;
   } else {
    alert('fail :(');
   }
   return false;
  });
 });
</script>

 

 

This is pretty bizarre.  I'm trying to find a way to work around.  If you have any ideas please let me know.  Btw, this happens whether I use 'window.' before location or not,  and also happens whether I use location.href or location.replace.

 

Should I post a bug report somewhere?

 

 

jason

Best Answer chosen by Admin (Salesforce Developers) 
aballardaballard

The "<" in the for loop is somehow confusing the page parser because it normally starts a tag. 

You may be able to use &lt;  to avoid the confusion, or maybe changing to i <= 6 or 7 > i  would work...

 

 

All Answers

aballardaballard

The "<" in the for loop is somehow confusing the page parser because it normally starts a tag. 

You may be able to use &lt;  to avoid the confusion, or maybe changing to i <= 6 or 7 > i  would work...

 

 

This was selected as the best answer
JasonGablerJasonGabler

 

I believe you correctly assessed the source of the problem. Unfortunately,  using an &lt; does not get translated by the VF compiler into a < and so the browser's Javascript compiler gets upset.

 

jason

JasonGablerJasonGabler

Well, I think we've confirmed there's a bug.... following your advice as to the source of the problem, I created this work-around:

 

 

 

	  	var ids = new Array('#q1','#q2','#q3','#q4','#q5','#q6')
			for( var i in ids) {
	  		if (!$(ids[i]).attr('checked')) {
	  			pass = false;
	  		}
	  	}

 

 

If the "ids" array needed to be dynamic, I'm not sure what could be done at the moment.

 

jason

 

JasonGablerJasonGabler

So where would I report this bug?

aballardaballard

Did you try my other suggestion of jsut reworing the expression to not use < (e.g.  7> i ) ?

 

You should file a support case for this.  I believe it is a known issue but a case will get it a higher priority.