i am working on an adapted version of Adam Maschek’s excellent image map tool. The new functionality i have added are left/top/width/height input boxes so that you can have pixel control over the hotspot position/size. I have got it working fine in FF and Chrome but the issue i am having is in IE 7/8 where it just will not retrieve the value of the input box on change.
Here is the function where the issue is occuring:
function gui_dimension_change(e) {
function changeAreaPos(areaNum, inputVal, cssAttrib, coordPos) {
var coordsBox = document.getElementsByClassName('img_coords')[areaNum],
newCoordsVal = coordsBox.value.split(","),
newWidth = "",
newHeight = "",
imCode = imcodeContainer.value,
pattern = imCode.match(/\d+,\d+,\d+,\d+/g);
myimgmap.areas[areaNum].style[cssAttrib] = inputVal;
if (cssAttrib === "left" || cssAttrib === "top") {
myimgmap.areas[areaNum].label.style[cssAttrib] = inputVal;
newCoordsVal[coordPos] = inputVal;
} else if (cssAttrib === "width") {
myimgmap.areas[areaNum].width = inputVal;
newWidth = parseInt(newCoordsVal[0]) + parseInt(inputVal);
newCoordsVal[coordPos] = newWidth;
} else if (cssAttrib === "height") {
myimgmap.areas[areaNum].height = inputVal;
newHeight = parseInt(newCoordsVal[1]) + parseInt(inputVal);
newCoordsVal[coordPos] = newHeight;
}
newCoordsVal = newCoordsVal.join(",");
myimgmap.areas[areaNum].lastInput = newCoordsVal;
coordsBox.value = newCoordsVal;
imCode = imCode.replace(pattern[areaNum], newCoordsVal);
imcodeContainer.value = imCode;
};
// alert(this);
// alert(this.parentNode);
// alert(this.parentNode.id);
var inputParent = this.parentNode,
inputVal = this.value,
whichBox = this.name,
areaNum = inputParent.id.replace("img_area_", ""),
imcodeContainer = document.getElementById('html_container');
switch(whichBox)
{
case "img_left":
changeAreaPos(areaNum, inputVal, "left", 0);
break;
case "img_top":
changeAreaPos(areaNum, inputVal, "top", 1);
break;
case "img_width":
changeAreaPos(areaNum, inputVal, "width", 2);
break;
case "img_height":
changeAreaPos(areaNum, inputVal, "height", 3);
break;
}
}
The function is called like so:
myimgmap.addEvent(props[id].getElementsByTagName('input')[5], 'change', gui_dimension_change);
myimgmap.addEvent(props[id].getElementsByTagName('input')[6], 'change', gui_dimension_change);
myimgmap.addEvent(props[id].getElementsByTagName('input')[7], 'change', gui_dimension_change);
myimgmap.addEvent(props[id].getElementsByTagName('input')[8], 'change', gui_dimension_change);
So on the change event i can’t set inputParent with this.parentNode, and can’t grab the value of the input box with this.value either. Works in FF/Chrome but not IE 7/8, any ideas why IE has a problem with parentNode and getting the value?
OK, i figured out the solution in case anyone cares. It was all because IE handles event targets differently to other browsers, so i did the following:
and used obj instead of this.
Stupid IE!!!