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
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
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • 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.