IE6 failing to set checkbox or radio buttons

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • clivethebadger
    New Member
    • Feb 2008
    • 12

    IE6 failing to set checkbox or radio buttons

    Hi,
    I've got javascript code which uses a basic logical statement to determine whether a checkbox or radio button should be set to checked:

    radio.checked = (map.getLayer(d ivId) == map.baseLayer);

    Firefox has no trouble with this, but IE6 doesn't check anything!

    Any idea why this might be?

    Cheers,
    Jon
  • gits
    Recognized Expert Moderator Expert
    • May 2007
    • 5388

    #2
    please show more of your code ... what does getLayer do? and what is baseLayer? and what is map?

    kind regards

    Comment

    • clivethebadger
      New Member
      • Feb 2008
      • 12

      #3
      The code is using OpenLayers javascript client for displaying maps.

      Basically map.getLayer(di vId) just returns a map layer using the given ID and map.baseLayer is the current visible layer. I'm just checking to see if they are equal.

      The logical statement definitely works (even in IE) because when I output it in an alert is displays the correct value of true or false.

      Jon

      Comment

      • clivethebadger
        New Member
        • Feb 2008
        • 12

        #4
        Sorry to post again, just though I should post the whole code section. Basically it's a for-loops for contructing a list of map layers:

        Code:
        for (var i=0; i<baseLayers.length; i++)
        {
        	var divId = baseLayers[i].id;
        	//individual baselayer
        	var baseLayerElem = document.createElement("li");
        		var radio = document.createElement('input');
        			radio.type = 'radio';
        			radio.name = 'base';
        			radio.value = divId;
        			radio.id = divId + "Rad";
        			radio.onclick = Function("ChangesClient.layerOptionsPanel.toggleBase('"+divId+"')");
        			radio.checked = (map.getLayer(divId) == map.baseLayer);
        		var a = document.createElement('a');
        			a.className = 'ccLink';
        			a.href = "javascript:ChangesClient.Util.toggleDiv('" + divId + "')";
        			a.innerHTML = baseLayers[i].name;
        		var optionsDiv = document.createElement('div');
        			optionsDiv.className = 'ccLayerOptionsBaseLayerOptions';
        			optionsDiv.id = divId;
        			optionsDiv.innerHTML = "Baselayer options for" + divId;
        			optionsDiv.style.display = 'none';
        		baseLayerElem.appendChild(radio);
        		baseLayerElem.appendChild(a);
        		baseLayerElem.appendChild(optionsDiv);
        	baseLayerList.appendChild(baseLayerElem);
        	this.layerList.push(divId);
        }

        Comment

        • acoder
          Recognized Expert MVP
          • Nov 2006
          • 16032

          #5
          IE has a problem with dynamically appended checkboxes/radio buttons. It doesn't respect the checked property. There are two solutions, either use defaultChecked or check it after appending. I've mentioned some of these bugs/quirks in a howto/article.

          Comment

          • clivethebadger
            New Member
            • Feb 2008
            • 12

            #6
            Thank you very much, I've just added the element ID's to a list and looped through it at the end calling

            document.getEle mentById(ID).ch ecked = true;

            The most I mess around with JS, the more I think that IE is a pain in the arse.

            Cheers,
            Jon

            Comment

            • acoder
              Recognized Expert MVP
              • Nov 2006
              • 16032

              #7
              A pain indeed. Glad it helped.

              Comment

              Working...