Jump to content

adding an event


cleary1981

Recommended Posts

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);

}

 

Link to comment
https://forums.phpfreaks.com/topic/113200-adding-an-event/
Share on other sites

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.

Link to comment
https://forums.phpfreaks.com/topic/113200-adding-an-event/#findComment-581908
Share on other sites

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.