1

I Have a 2 Address FromAddress and ToAddress. I have a one checkbox on visual force page like SameAsFromAddress. When I click on that checkbox I'm copying address using jQuery, but this jQuery is not working only in IE8 and working fine in all browsers like IE10, Chrome and Mozilla.

<apex:page standardController="Account" extensions="MyController">
    <apex:form>
        <apex:pageBlock>
            <apex:pageBlockButtons>
                <apex:inputCheckbox styleClass="copyLink">Copy</apex:inputcheckbox>
            </apex:pageBlockButtons>
            <apex:pageBlockSection>
                <apex:repeat value="{!fromFields}" var ="f">
                    <apex:inputField value="{!Account[f]}" styleClass="{!f}"/>
                </apex:repeat>
                <apex:repeat value="{!toFields}" var ="f">
                    <apex:inputField value="{!Account[f]}" styleClass="{!f}"/>
                </apex:repeat>
            </apex:pageBlockSection>
        </apex:pageBlock>
    </apex:form>
<apex:includeScript value="//code.jquery.com/jquery-1.11.0.min.js"/>
<script>
var j$ = jQuery.noConflict();
var addClick = function() {
   j$('.copyLink').click(function(e) {
       var fromFields = [<apex:repeat value="{!fromFields}" var ="f">'{!f}',</apex:repeat>];
       var toFields = [<apex:repeat value="{!toFields}" var ="f">'{!f}',</apex:repeat>];
       for (var i = 0; i < fromFields.length; i++) {
           j$('.' + toFields[i]).val(j$('.' + fromFields[i]).val());
       }

   });
};
j$(document).ready(addClick);
</script>
  • 3
    JQuery generally works in IE8. Can you spot any javascript error messages in IE? And could you please share the relevant parts of your javascript? – FrankZ May 29 '14 at 11:43
  • FWIW, you shouldn't be supporting IE8. If your IT team hasn't moved everyone to IE9, they're risking zero-day bugs and all sorts of issues with a no-longer-supported browser. – sfdcfox May 30 '14 at 15:28
  • @sfdcfox you're right, but sometimes it's not so easy. – FrankZ May 31 '14 at 8:49
2

IE is a bit fussy about <script> tags. Try:

<script  type="text/javascript">

Also: Your arrays will be generating with stray commas at the end:

var fromFields = [<apex:repeat value="{!fromFields}" var ="f">'{!f}',</apex:repeat>];

will lead to something like

var fromFields = ['one','two','three',];

Not sure if that matters or not, but it might be another thing to look at.

  • That had something to do with it: this question answers that. – sfdcfox May 30 '14 at 15:29
  • @sfdcfox as in IE8 objects to the trailing comma? – codeulike May 30 '14 at 16:22
  • As in how to avoid the trailing comma to begin with. The main factor with Bujji's problems stem from the fact that they don't want to "add code to the controller", so they'd rather bloat their VF page and view state size with expressions and generally try to make their life more complicated than it has to be. – sfdcfox May 30 '14 at 16:26

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.