Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Chris Miller on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

I.E7 object does not support this property or method

Status
Not open for further replies.

yorkshireboy

Programmer
Sep 14, 2007
3
GB
Hi the code listed below works ok in Firefox but I.E 7 and I jjust get an annoying "object does not support this property or method". It occurs when you click the black white box for the 2nd time, everything works as it should for the first time! Then we get the error, I have tried adding alert boxes to see where it gets to but the alerts never get fired.

anybody got any ideas

<%@ Page Language="C#" AutoEventWireup="true" CodeFile="xx.aspx.cs" Inherits="xx" %>

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "
<html xmlns=" >
<head runat="server">
<title>Untitled Page</title>
<script>
var cpPos
var cpMouseDown
var baseColor = {r:255, g:255, b:255};
var cpColor
var colorNames = {'aliceblue':'F0F8FF','darkslategray':'2F4F4F','lightsalmon':'FFA07A','palevioletred':'DB7093','anti quewhite':'FAEBD7','darkturquoise':'00CED1','lightseagreen':'20B2AA','papayawhip':'FFEFD5','aqua':'0 0FFFF','darkviolet':'9400D3','lightskyblue':'87CEFA','peachpuff':'FFDAB9','aquamarine':'7FFFD4','dee ppink':'FF1493','lightslategray':'778899','peru':'CD853F','azure':'F0FFFF','deepskyblue':'00BFFF','l ightsteelblue':'B0C4DE','pink':'FFC0CB','beige':'F5F5DC','dimgray':'696969','lightyellow':'FFFFE0',' plum':'DDA0DD','bisque':'FFE4C4','dodgerblue':'1E90FF','lime':'00FF00','powderblue':'B0E0E6','black' :'000000','firebrick':'B22222','limegreen':'32CD32','purple':'800080','blanchedalmond':'FFEBCD','flo ralwhite':'FFFAF0','linen':'FAF0E6','red':'FF0000','blue':'0000FF','forestgreen':'228B22','magenta': 'FF00FF','rosybrown':'BC8F8F','blueviolet':'8A2BE2','fuchsia':'FF00FF','maroon':'800000','royalblue' :'4169E1','brown':'A52A2A','gainsboro':'DCDCDC','mediumaquamarine':'66CDAA','saddlebrown':'8B4513',' burlywood':'DEB887','ghostwhite':'F8F8FF','mediumblue':'0000CD','salmon':'FA8072','cadetblue':'5F9EA 0','gold':'FFD700','mediumorchid':'BA55D3','sandybrown':'F4A460','chartreuse':'7FFF00','goldenrod':' DAA520','mediumpurple':'9370DB','seagreen':'2E8B57','chocolate':'D2691E','gray':'808080','mediumseag reen':'3CB371','seashell':'FFF5EE','coral':'FF7F50','green':'008000','mediumslateblue':'7B68EE','sie nna':'A0522D','cornflowerblue':'6495ED','greenyellow':'ADFF2F','mediumspringgreen':'00FA9A','silver' :'C0C0C0','cornsilk':'FFF8DC','honeydew':'F0FFF0','mediumturquoise':'48D1CC','skyblue':'87CEEB','cri mson':'DC143C','hotpink':'FF69B4','mediumvioletred':'C71585','slateblue':'6A5ACD','cyan':'00FFFF','i ndianred':'CD5C5C','midnightblue':'191970','slategray':'708090','darkblue':'00008B','indigo':'4B0082 ','mintcream':'F5FFFA','snow':'FFFAFA','darkcyan':'008B8B','ivory':'FFFFF0','mistyrose':'FFE4E1','sp ringgreen':'00FF7F','darkgoldenrod':'B8860B','khaki':'F0E68C','moccasin':'FFE4B5','steelblue':'4682B 4','darkgray':'A9A9A9','lavender':'E6E6FA','navajowhite':'FFDEAD','tan':'D2B48C','darkgreen':'006400 ','lavenderblush':'FFF0F5','navy':'000080','teal':'008080','darkkhaki':'BDB76B','lawngreen':'7CFC00' ,'oldlace':'FDF5E6','thistle':'D8BFD8','darkmagenta':'8B008B','lemonchiffon':'FFFACD','olive':'80800 0','tomato':'FD6347','darkolivegreen':'556B2F','lightblue':'ADD8E6','olivedrab':'6B8E23','turquoise' :'40E0D0','darkorange':'FF8C00','lightcoral':'F08080','orange':'FFA500','violet':'EE82EE','darkorchi d':'9932CC','lightcyan':'E0FFFF','orangered':'FF4500','wheat':'F5DEB3','darkred':'8B0000','lightgold enrodyellow':'FAFAD2','orchid':'DA70D6','white':'FFFFFF','darksalmon':'E9967A','lightgreen':'90EE90' ,'palegoldenrod':'EEE8AA','whitesmoke':'F5F5F5','darkseagreen':'8FBC8F','lightgrey':'D3D3D3','palegr een':'98FB98','yellow':'FFFF00','darkslateblue':'483D8B','lightpink':'FFB6C1','paleturquoise':'AFEEE E','yellowgreen':'9ACD32'};

function hex(c){
c=parseInt(c).toString(16);
return c.length<2?"0"+c:c
}

function cpMouseDown(evt)
{
var fColorImg = document.getElementById("fColorImg");
cpPos = getPosition(fColorImg);
cpMouseDown = true;
return false;


}

function cpMouseUp(evt)
{
cpMouseDown = false;
}

function cpMouseClick(evt)
{

ev = evt || window.event;

var mousePos = mouseCoordinates(ev);

var x = mousePos.x-cpPos.x-1;
var y = mousePos.y-cpPos.y-1;

setCPColor(getGradientColor(x, y, baseColor));
}



function getPosition(obj)
{
var left = 0;
var top = 0;

while (obj.offsetParent){
left += obj.offsetLeft;
top += obj.offsetTop;
obj = obj.offsetParent;
}
left += obj.offsetLeft;
top += obj.offsetTop;

return {x:left, y:top};
}

function mouseCoordinates(ev){
ev = ev || window.event;

if(ev.pageX || ev.pageY)
return {x:ev.pageX, y:ev.pageY};
return {x:ev.clientX + document.body.scrollLeft - document.body.clientLeft,
y:ev.clientY + document.body.scrollTop - document.body.clientTop};
}

function setCPColor(color)
{

var rInput = document.getElementById("rInput");
var gInput = document.getElementById("gInput");
var bInput = document.getElementById("bInput");
var websafeCheckbox = document.getElementById("websafeCheckbox")
var websafeImg = document.getElementById("websafeImg")
var curColorDiv = document.getElementById("curColorDiv")
if(color.srcElement || color.target) color=null;
if(color && (!color.r && (color.r!=0))) color = parseColor(color);
if(!color){

color = {
rarseInt(rInput.value),
garseInt(gInput.value),
barseInt(bInput.value)
}

}

var wsColor = getWebSafeColor(color)

if(wsColor && !websafeCheckbox.checked){

websafeImg.style.display = 'block';
websafeImg.style.backgroundColor = '#'+hex(wsColor.r)+hex(wsColor.g)+hex(wsColor.b);

}else{

if(wsColor && websafeCheckbox.checked) color = wsColor;
websafeImg.style.display = 'none';
}

rInput.value = color.r;
gInput.value = color.g;
bInput.value = color.b;

cpColor = color;
curColorDiv.style.backgroundColor = '#'+hex(color.r)+hex(color.g)+hex(color.b);
}


function parseColor(text){
if(colorNames[text.toLowerCase()]) text = colorNames[text.toLowerCase()];
if(/^\#?[0-9A-F]{6}$/i.test(text)){
return {
r: eval('0x'+text.substr(text.length==6?0:1, 2)),
g: eval('0x'+text.substr(text.length==6?2:3, 2)),
b: eval('0x'+text.substr(text.length==6?4:5, 2))
}
}
return {r:255, g:0, b:0};
}

function getWebSafeColor(color)
{
var rMod = color.r % 51;
var gMod = color.g % 51;
var bMod = color.b % 51;

if((rMod==0) && (gMod==0) && (bMod==0)) return false;

var wsColor={};

wsColor.r=(rMod<=25?Math.floor(color.r/51)*51:Math.ceil(color.r/51)*51);
wsColor.g=(gMod<=25?Math.floor(color.g/51)*51:Math.ceil(color.g/51)*51);
wsColor.b=(bMod<=25?Math.floor(color.b/51)*51:Math.ceil(color.b/51)*51);

return wsColor;
}
function getGradientColor(x, y, Base){
x = x<0?0:x>255?255:x;
y = y<0?0:y>255?255:y;

var r = Math.round((1-(1-(Base.r/255))*(x/255))*(255-y));
var g = Math.round((1-(1-(Base.g/255))*(x/255))*(255-y));
var b = Math.round((1-(1-(Base.b/255))*(x/255))*(255-y));

return {r:r, g:g, b:b};
}

}
</script>

</head>
<body>
<form id="form1" runat="server">

<div id="fColorPicker" style="border:1px solid #000;width:397px;height:305px;position:relative;background-color:#E0DFE3;">
<div style="position:absolute;top:3px;left:8px;">Select Color:</div>
<img src="Images/cp_lg_background.png" height="260" width="260" style="position:absolute;top:20px;left:8px;" galleryimg="no"/>
<img id="fColorImg" src="Images/cp_lg_overlay.png" width="256", height="256" style='cursor:crosshair;position:absolute;top:22px;left:10px;' galleryimg="no" onmousedown="cpMouseDown(event)" onmouseup="javascript:cpMouseUp(event)" onclick="javascript:cpMouseClick(event)" />
<img id="colorSlider" src="Images/cp_color_slider.png" width="23" height="260" style="cursorointer;position:absolute;top:20px;left:280px;z-index:2;"/>
<img id="Arrows" src="Images/cp_arrows.gif" width="41" height="9" style="cursorointer;position:absolute;top:18px;left:271px;z-index:1;"/>
<img src="Images/cp_cur_color_background.png" width="62" height="70" style="position:absolute;top:20px;left:315px;" />
<img id="websafeImg" src="Images/cp_web_safe.gif" width="14" height="28" style="cursorointer;position:absolute;top:62px;left:380px;" alt="Click to Select Web Safe Color"/>
<div id="curColorDiv" style="z-index:2;position:absolute;top:22px;left:317px;width:58px;height:33px;"></div>
<div id="OrigColorDiv" style="z-index:2;cursorointer;position:absolute;top:55px;left:317px;width:58px;height:33px;"></div>
<div style="position:absolute;top:103px;left:315px;">R:</div>
<div style="position:absolute;top:128px;left:315px;">G:</div>
<div style="position:absolute;top:153px;left:315px;">B:</div>
<input id="rInput" style="position:absolute;top:100px;left:330px;width:47px;" />
<input id="gInput" style="position:absolute;top:125px;left:330px;width:47px;" />
<input id="bInput" style="position:absolute;top:150px;left:330px;width:47px;" />
<input id="OK" type="button" style="position:absolute;bottom:50px;left:315px;width:77px;" value="OK" />
<input id="Cancel" type="button" style="position:absolute;bottom:25px;left:315px;width:77px;" value="Cancel" />
<input id="websafeCheckbox" type="checkbox" style="position:absolute;top:280px;left:4px;" />
<div style="position:absolute;top:284px;left:25px;">Only Web Colors</div>
</div>
</form>
</body>
</html>
 
Could you identify the "black white box" in your code for us - maybe let us know the ID of the element with the onclick on it.

As an aside:

You don't need to include javascript: in your onclicks, onmousedowns etc (in fact it is not legit to do so).

Also... confirm your code validates first! Use w3c validator service in the first instance.

Cheers,
Jeff

[tt]Jeff's Blog [!]@[/!] CodeRambler
[/tt]

Make sure your web page and css validates properly against the doctype you have chosen - before you attempt to debug a problem!

FAQ216-6094
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top