Topic: Disable left-click within a div

Hi guys
I please need some help or some recommendations on how to do the following.
I’m using a simple js function to switch between background images within a div witch act as buttons. The functions are called from one textfield via onclick and onblur.

Code: PHP

function divActive(divId) {

var div = document.getElementById(divId);

div.style.backgroundImage="url(img/gif/button_add.gif)";

div.style.cursor="pointer";

}

function divInActive(divId) {

var div = document.getElementById(divId);

div.style.backgroundImage="url(img/gif/button_add_grey.gif)";

div.style.cursor="";

}



<div id=" addDiv " style="width:20px; height:20px; background-image:url(img/gif/button_delete_gray.gif)" onclick="xajax_addFunction();">&nbsp;</div>

 

<input name=" add" type="text" id=" add" size="30" value="" onclick=" divActive('addDiv'); " onblur=" divInActive('addDiv');" />

 

What I want to accomplish is to only be able to run a onclick function (xajax_addFunction();)when the div is “active”. My logic tells me I can only accomplish this by either disabling left-click within the div when it’s “InActive” and enabling it again when the div is “active” or to have the onclick="xajax_addFunction()" within the divActive function (witch I don’t know if it’s possable).

Please any help in how to disable left-click only within the div or how to put the onclick within the divActive function will be appreciated.

Last edited by rizla_za (2009-06-14 9:49:14 AM)

Re: Disable left-click within a div

Resolved - tanks all for reading...

for those who hase the same problem:

Code: PHP

function divActive(divId) {

var div = document.getElementById(divId);

div.style.backgroundImage="url(img/gif/button_add.gif)";

div.style.cursor="pointer";

div.onclick=function(){xajax_addFunction()};

}