You need to sign in to do that
Don't have an account?
mejoe
javascript in vforce page causing validation errors when saving
I need to implement a visualforce page that serves a javascript text file. This is based on this blog entry: http://www.nimbleuser.com/blogs/Developers/Developers/Visualforce_Static_Resource_Alternative.aspx
<apex:page contentType="text/javascript" cache="false" expires="0"> //alert('ping'); if (document.getElementById('cas21') != null) { var divsInthepage = document.getElementsByTagName("DIV"); for (i = 40; i < divsInthepage.length; i++) { if (divsInthepage[i].innerHTML.indexOf("topButtonRow", 1) > 1 && divsInthepage[i].innerHTML.indexOf("requiredBlock", 0) < 1) { divsInthepage[i].innerHTML = '<table border="0" cellpadding="0" cellspacing="0"><tr><td class="pbTitle"><img src="/s.gif" alt="" width="1" height="1" class="minWidth" title="" /><h2 class="mainTitle">Case Edit</h2></td><td class="pbButton" id="topButtonRow"><input value="Submit" class="btn" title="Submit" name="save" type="submit" /> <input value="Cancel" class="btn" title="Cancel" name="cancel" type="submit" /></td>' } if (divsInthepage[i].innerHTML.indexOf("bottomButtonRow", 1) > 1 && divsInthepage[i].innerHTML.indexOf("requiredBlock", 0) < 1) { divsInthepage[i].innerHTML = '<table border="0" cellpadding="0" cellspacing="0"><tr><td class="pbTitle"><img src="/s.gif" alt="" width="1" height="1" class="minWidth" title="" /></td><td class="pbButtonb" id="bottomButtonRow"><input value="Submit" class="btn" name="save" tabindex="11" title="Submit" type="submit" /> <input value="Cancel" class="btn" name="cancel" title="Cancel" type="submit" /></td></tr></table>' } if (divsInthepage[i].innerHTML.indexOf("Assign using active assignment rules", 1) > 1 && divsInthepage[i].innerHTML.indexOf("requiredBlock", 0) < 1) { divsInthepage[i].innerHTML = '<table class="detailList" border="0" cellpadding="0" cellspacing="0"><tr class="detailRow last"><td colspan="4"><input checked="checked" id="cas21" name="cas21" tabindex="10" type="checkbox" value="1" /></td></tr></table>' } if (divsInthepage[i].innerHTML.indexOf("<h3>Optional<span", 1) > 1 && divsInthepage[i].innerHTML.indexOf("requiredBlock", 0) < 1) { divsInthepage[i].innerHTML = '' } { } } </apex:page>
It seems that any occurence of "<" or "&" is triggering the issue. I discovered that setting the version number for the file to 18 fixed the issue. What can I do to format the javascript so that it does not cause validation errors?
What error are you getting?
"The content of elements must consist of well-formed character data or markup." as well as an error about "&" needing an entity after it.
Prior to v18, Visualforce did not enforce XHTML formatting. After v18, all Visualforce markup must be valid XHTML. Javascript in a Visualforce page is not valid w/o a <script> tag.
What you're missing is that the blog's example defines Javascript functions. If you want your Javascript executed during page loading, wrap your Javascript in a function and call it immediately. For example:
i.e.
due to all the xhtml rendering errors that'll occur with any characters like "&&", etc?