cleary1981 Posted July 4, 2008 Share Posted July 4, 2008 Is it possible to add an onmousedown event to the objects i am creating in the code below? function showObject() { if (request.readyState == 4) { var returned = request.responseText; var splitResult = returned.split(" "); var h = splitResult[0]; var w = splitResult[1]; // the dimensions must be set to a scale as they are to big for the screen. 25px represents 100mm h = h/4; w = w/4; // this bit of code creates the new img object and sets the attributes var yy = document.getElementById("container"); var newImgElement = document.createElement("img"); //create a new img element newImgElement.className = "obj"; //for css reference newImgElement.src = "box.gif"; newImgElement.id = g_objName; newImgElement.border = 1; newImgElement.height = h; newImgElement.width = w; yy.appendChild(newImgElement); } Quote Link to comment Share on other sites More sharing options...
corbin Posted July 4, 2008 Share Posted July 4, 2008 Assigning an onmousedown function is fairly straight forward. newImgElement.onmousedown = SomeFunction; Please note that where SomeFunction is, Javascript has to recognize it as a function reference. For example, if you put SomeFunction(), it would assign the return of SomeFunction() to the onmousedown event. Quote Link to comment Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.