views:

17

answers:

3

On my webpage I have images that function as checkboxes (image switch and set hidden form property value). It works in every browser except IE6. Does anybody have a clue what is causing this problem?

The code:

    function flip(element) { 
      var formElement = document.getElementById(element + "Form");
      var imgElement = document.getElementById(element);
      if (formElement.value == 1) { 
       formElement.value = 0;
       imgElement.src = "images/"+element+".png";
      } else {
       formElement.value = 1;
       imgElement.src = "images/"+element+"2.png";
      }
     }

and html example:

<input type="hidden" id="inteligencaForm" name="inteligenca" value="0">
<img id="inteligenca" src="images/inteligenca.png" class="pngfix" onClick="flip('inteligenca')">
A: 

What does it do? Nothing?

Try: <img id="inteligenca" src="images/inteligenca.png" class="pngfix" onClick="flip('inteligenca'); event.returnValue=false; return false;">

Bal
+1  A: 

Your code looks like it'll work properly. The error is probably coming from the pngfix you're using.

laurencek
it was a combination of pngfix and getElementByID bug.
Null
A: 

If I am not mistaken, getElementByID is broken on IE <8 and it is confusing the name="inteligenca" in your input with id="inteligenca" in image.

Try removing "name" from the "input"

jamietre
I just confirmed this in a test, remove the "name" from input and it works fine in IE6
jamietre