473,503 Members | 3,497 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

how do you prevent the onclick action from being fired in IE

14 New Member
How do I in IE prevent the onclick action from being fired when I am done dragging?
have tried "window.event.cancelBubble = true", for onmouseup , onmousedown, and onmousemove handlers. The onclick sort action always seems to get fired. Any help would be greatly appeciated.
The following demo is sortable and resizable. I basically don't want the onclick action to be fired if I am resizing a column.

Steve


[HTML]<HTML>
<HEAD>
<style>
h1, h2{
font-family:Verdana, Arial, Helvetica, sans-serif;
font-size:13px;

}
.move
{
width:100%;
background-color:#99CCFF;
border-bottom:1px solid blue;
font-size:14px;
font-family:vardana;
font-color:"#33CCAA";
text-align:center;
}

.info
{
width:100%;
background-color:#99CCFF;
border-top:1px solid blue;
font-size:13px;
font-family:vardana;
font-color:"#33CCAA";
}

.panel2{
width:150; position:absolute; border:1px solid blue; left:500; top:200; font-size:13px; font-family:vardana;}

.panel{
width:150; position:absolute; border:1px solid blue; left:350; top:200; font-size:13px; font-family:vardana;}
.panel a:visited{color:blue;}

.panel a{text-decoration:none;color:blue}

.panel a:hover{text-decoration:none;}



#panel a.visited{

text-decoration:none;

}

.menu

{

width:100%;

background-color:lightyellow;

font-size:13px;

font-family:vardana;

}

</style>

<!--[if IE]>
<style type="text/css">
div.scrollable {
/* shrink the window, adjust for the 2 border pixels */
height:expression( this.getElementsByTagName('TABLE')[0].clientHeight >= 80 ? "80px": "auto" );
overflow-x: visible;
overflow-y: auto;
}

div.scrollable table {
/* adjust for the 17 pixels for the scrollbar */
width: expression(this.parentNode.offsetWidth-17);
}

/* set the table row */
div.scrollable table thead tr {
position: relative;
/* this fixes IE header jumping bug */
top: expression( this.parentNode.parentNode.parentNode.scrollTop + 'px' );
}
</style>
<![endif]-->

<!-- if mozilla -->
<style type="text/css">
html>body div.TableContainer table tbody {
height: 20px;
overflow: auto;
}

/* add 17 for the scrollbar */
html>body div.TableContainer div.scrollbarCol {
width:17px;
}
</style>

<script type="text/javascript" src="http://www.kryogenix.org/code/browser/sorttable/sorttable.js" >
</script>

<SCRIPT LANGUAGE="JavaScript">

N = (document.all) ? 0 : 1;
var ob;
var over = false;
var over_id ="";
var iEdgeThreshold = 10;

function TableResize_findPos(obj) {
var curleft = curtop = 0;
if (obj.offsetParent) {
curleft = obj.offsetLeft;
curtop = obj.offsetTop;
while (obj = obj.offsetParent) {
curleft += obj.offsetLeft;
curtop += obj.offsetTop;
}
}
return [curleft,curtop];
}

/* Function that tells me if on the border or not */
function TableResize_isOnBorderLeft( objTable, objTh,event){
var left = objTh.offsetLeft;
var pos = TableResize_findPos(objTable);
var absLeft = pos[0] + left;

if( event.clientX < (absLeft + iEdgeThreshold) ){
return 1;
}
return 0;
}

function TableResize_isOnBorderRight( objTable, objTh,event){
var width = objTh.offsetWidth;
var left = objTh.offsetLeft;
var pos = TableResize_findPos(objTable);
var absRight = pos[0] + left + width;

if( event.clientX > (absRight - iEdgeThreshold) ){
return 1;
}
return 0;
}

function TableResize_getNodeName(objReference,nodeName)
{
var oElement = objReference;
while (oElement != null && oElement.tagName != null && oElement.tagName != "BODY") {
if (oElement.tagName.toUpperCase() == nodeName) {
return oElement;
}
oElement = oElement.parentNode;
}
return null;
}


function do_resize(objTh,event){
if(event == null){
event = window.event;
}
var objTable = TableResize_getNodeName(objTh, "TABLE");
if( TableResize_isOnBorderLeft( objTable, objTh,event) ){
objTh.style.cursor="e-resize";
return true;
}
else if( TableResize_isOnBorderRight( objTable, objTh,event) ){
objTh.style.cursor="e-resize";
return true;
}

objTh.style.cursor="";
return false;
}

function MD(e) {
MOUSTSTART_X=event.clientX;
MOUSTSTART_Y=event.clientY;
if (over){
if (N) {
ob = document.getElementById(over_id);
X=e.layerX;
Y=e.layerY;
return false;
}

else{

ob = document.getElementById(over_id);
ob2 = document.getElementById("MAINTABLE");
obwidth=parseInt(ob.style.width);
obwidth2=parseInt(ob2.style.width);
X=event.offsetX;
Y=event.offsetY;

}

}
}


function MM(e) {

if (ob) {
if (N) {
ob.style.top = e.pageY-Y;
ob.style.left = e.pageX-X;
}
else{
st=event.clientX-MOUSTSTART_X+obwidth;
st2=event.clientX-MOUSTSTART_X+obwidth2;

if(st>=30){
ob.style.width=st;
ob2.style.width=st2;
document.getElementById("status").innerHTML=st;
}
document.selection.empty();
}
}
}

function MU(e) {

if(ob != null){
document.selection.empty();
ob = null;
}
}

if (N) {
document.captureEvents(Event.MOUSEDOWN | Event.MOUSEMOVE | Event.MOUSEUP);
}

document.onmousedown = MD;
document.onmousemove = MM;
document.onmouseup = MU;
</script>


</HEAD>

<BODY>
<!--
YOU MUST HAVE TO DEFINE WIDTH ON STYLE TAB.. if you leave NULL
IT RETURNS .. ERROR..
-->
<H1>RESIZABLE TABLE COLUMN</H1>

<table style="border: 1px gray solid">
<tr>
<td>
<div class="scrollable">

<TABLE border="1" STYLE="width:500px; overflow:hidden; table-layout:fixed" ID="MAINTABLE" class="sortable">

<THEAD>

<TR>

<TH id="panel0" class='move' onmousemove="over=do_resize(this);over_id='panel0' " onmouseover="over=do_resize(this);over_id='panel0' " onmouseout='over=false;' style='width:100px; overflow:hidden'>CO0</TH>

<TH id="panel1" class='move' onmousemove="over=do_resize(this);over_id='panel1' " onmouseover="over=do_resize(this);over_id='panel1' " onmouseout='over=false;' style='width:100px; overflow:hidden'>CO1</TH>

<TH id="panel2" class='move' onmousemove="over=do_resize(this);over_id='panel2' " onmouseover="over=do_resize(this);over_id='panel2' " onmouseout='over=false;' style='width:100px; overflow:hidden'>CO2</TH>

<TH id="panel3" class='move' onmousemove="over=do_resize(this);over_id='panel3' " onmouseover="over=do_resize(this);over_id='panel3' " onmouseout='over=false;' style='width:100px; overflow:hidden'>CO3</TH>

<TH id="panel4" class='move' onmousemove="over=do_resize(this);over_id='panel4' " onmouseover="over=do_resize(this);over_id='panel4' " onmouseout='over=false;' style='width:100px; overflow:hidden'>CO4</TH>

</TR>
</THEAD>
<TBODY>
<TR>

<TD>1_0</TD>


<TD><input type="text" value="this is a very long text string" style="width:100%" ></TD>


<TD>1_2</TD>


<TD>1_3</TD>


<TD>1_4</TD>


</TR>


<TR>

<TD>2_0</TD>


<TD>2_1</TD>


<TD>2_2</TD>


<TD>2_3</TD>


<TD>2_4</TD>


</TR>


<TR>

<TD>3_0</TD>


<TD>3_1</TD>


<TD>3_2</TD>


<TD>3_3</TD>


<TD>3_4</TD>


</TR>


<TR>

<TD>4_0</TD>


<TD>4_1</TD>


<TD>4_2</TD>

<TD>4_3</TD>
<TD>4_4</TD>

</TR>
</TBODY>
</table>

</div>
</td>
</tr>
</table>
<div id="status"></div>
</HTML>[/HTML]
Nov 12 '07 #1
4 2192
gits
5,390 Recognized Expert Moderator Expert
hi ...

please don't post your email address here ... i removed it from the post for your own protection ...

kind regards
Nov 12 '07 #2
Dasty
101 Recognized Expert New Member
I briefly looked at your code. You can not tell browser to not fire events if you already attached event handlers for some of your elements / document. If you don't want to process them you got 2 choices:

1) deatttach (temporary or permantly) event handlers from objects you dont want to be processed
2) make some kind of "state" variables where you'll keep some kind of status and adjust code in handlers to act based on conditions stored in those variables. For example in your solution you'll create global variable "var i_just_moved_col = false" and adjust onclick handler to reflect it.

Stopping bubbling / prospecting will just tell the browser to not continue firing same event on higher / lower elements in structure.

Sorry I dont have time to give you exact solution, because it requires to dig http://www.kryogenix.org javascript file too (because exactly code in that include file is adding onclick handler on header cells)

Hope that helps
Nov 12 '07 #3
since
14 New Member
Dasty,
Thx for your replay. That was extremely helpful. I did notice that an alert statement caused the onclick event handler to be fired. Is it possible to fool change the location of the mouse pointer to a different location, e.g. onmouseup move to a location.

Steve
Nov 12 '07 #4
since
14 New Member
Dasty,
Typo
Thx for your replay. That was extremely helpful. I did notice that an alert statement caused the onclick event handler to be fired. Is it possible to fool change the location of the mouse pointer to a different location, e.g. onmouseup move to a location.

Steve
Thx for your replay. That was extremely helpful. I did notice that an alert statement caused the onclick event handler NOT to be fired. Is it possible to fool or change the location of the mouse pointer, e.g. onmouseup move to a location outside the resizing cell.
Nov 12 '07 #5

Sign in to post your reply or Sign up for a free account.

Similar topics

4
44908
by: Michael Hill | last post by:
I had this html: <tr id="action" title="click to do something" onclick="alert('mike');"> <td>a</td> <td>b</td> </tr> and it works when I click on the row, but when I try to add it...
3
2277
by: Ryan Liu | last post by:
Can someone give a sample to prevent a row from being deleted in a datatable? I tried e.Row.RejectChanges(); in dt_RowDeleting() but seems does not work. I need verify if there other data...
4
13529
by: sameergn | last post by:
Hi, I have an image in my HTML form which has onclick() handler. There is also a submit button and a text box. Whenever text box has focus and user presses enter, the onclick() event of...
17
5446
by: emma.sax | last post by:
Hi all, I have a form where we would like the user to input their email address twice, to ensure they've typed it correctly, as is found on most sign-ups I'm looking for a solution to the...
5
13937
by: Stuart Shay | last post by:
Hello All I am working on ASP.NET 1.1 Custom Pager that allows a User to Enter a Number in a TextBox and go to the page selected. Since the OnClick Event does not work in ASP.NET 1.1 for a...
3
6477
by: Michael_R_Banks | last post by:
I'm trying to dynamically build a table that allows users to remove rows when they click a corresponding button. For some reason, whenever I add the button to the table, it never fires the onclick...
13
323
by: Mtek | last post by:
Hi, We have a form defined with buttons like this: <a class="save_menu" href="javascript:document.Detail_Screen.action = 'savedata.php?screen=EDIT';document.Detail_Screen.submit();">Update</...
6
4137
by: Gustaf | last post by:
I'm working on a code generator for documentation of VBA projects. It outputs HTML docs, including simple JS. I don't have much experience with JS however, so I need some help with this sample...
2
2766
by: Num GG | last post by:
Hi all, Given this simple code: <div id="mydiv" ondblclick="alert(id)" //parent div Div4 bla bla bla bla on div 4 <div id="myembeddeddiv"ondblclick="alert(id)" // child div...
0
7192
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
7064
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
7261
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
7315
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
0
5559
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...
0
4665
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and...
0
3158
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The...
0
1492
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated ...
0
369
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.