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 Mike Lewis on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

event handler

Status
Not open for further replies.

cleary1981

Programmer
Jun 10, 2008
4
GB
Hi all,

I'm not sure of the terms I should be using but maybe you can understand what i am trying to do from my code.

My code generates an img object and defines the attributes. What I need to do is to add an event handler (onmousedown) to it. Has anyone any suggestions?


Code:
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; // set id=object until the object has been defined. must be renamed after to objName i think
	newImgElement.border = 1;
	newImgElement.height = h;
	newImgElement.width = w;
	
	yy.appendChild(newImgElement);


 
Code:
newImgElement.onmousedown=function(){/*your code here*/}
There may be scope issues to resolve, but you need to say what the handler is to do.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top