views:

16

answers:

2

Hi, I have Two fields, one textbox nad one Div element. I have onblur event for textbox, and onclick event for div element. when i click the div element the textbox's onblur event occurs and not the onclick event of div element. how to supress the onblur event when i click on the div element

Thanks in advance

A: 

try to use a semafore.

if the click event is triggered set the semafore to true and check the value in the blur event call. if true - do not perform the action.

after successfully performing the click event reset the semafore to false.

helle
A: 

Hi, I'm not sure what you are trying to do and is it right way or not. But this will solve your problem by using flag named "f":

<head>
<script type="text/javascript">
    var f = 0;
    function f1() {
        if (f == 0)
            alert('blur');
    }
    function f2() {
        alert('click');
    }
    function f3() {
        f = 1;
    }
    function f4() {
        f = 0;
    }
</script>
</head>
<body>
    <input type="text" onblur="f1();" />
    <div onclick="f2();" onmouseover="f3();" onmouseout="f4();">
        Click Me!
    </div>
</body>

Good luck!

Mehdi

related questions