IE6 javascript on click image swap problems
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;
im开发者_Go百科gElement.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')">
Your code looks like it'll work properly. The error is probably coming from the pngfix you're using.
What does it do? Nothing?
Try:
<img id="inteligenca" src="images/inteligenca.png" class="pngfix" onClick="flip('inteligenca'); event.returnValue=false; return false;">
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"
精彩评论