473,396 Members | 1,966 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,396 software developers and data experts.

how can i stop this??

I have some example code below where, when I click on the background of
the table I want one thing to happen (wilma), and when I click on the
text box I want one different thing to happen (fred).

....but when I click on the text box, both happen (fred, then wilma). I'm
guessing this is to do with event bubbling but I could be thoroughly
mistaken. Anyway, how can I stop it so when I click on the text box only
fred occurs?

<html>
<head>
<style>
table#wilma {
border-color: green;
border-style: solid;
border-width: 2px;
}
</style>
<script>
function init() {
document.getElementById("fred").onclick = function() { alert("fred"); };
document.getElementById("wilma").onclick = function() { alert("wilma"); };
}
</script>
</head>
<body onload="init();">
<form id="test" action="" method="post">
<table id="wilma">
<tr><td>&nbsp;</td></tr>
<tr><td><input type="text" name="fred" id="fred" value="testing"></td></tr>
<tr><td>&nbsp;</td></tr>
</table>
</form>
</body>
</html>
TIA

Ian
Jul 20 '05 #1
3 1180
Ian Richardson wrote on 07 feb 2004 in comp.lang.javascript:
I have some example code below where, when I click on the background
of the table I want one thing to happen (wilma), and when I click on
the text box I want one different thing to happen (fred).

...but when I click on the text box, both happen (fred, then wilma).
I'm guessing this is to do with event bubbling but I could be
thoroughly mistaken. Anyway, how can I stop it so when I click on the
text box only fred occurs?

<html>
<head>
<style>
table#wilma {
border-color: green;
border-style: solid;
border-width: 2px;
}
</style>
<script>
function init() {
document.getElementById("fred").onclick = function() { alert("fred");
}; document.getElementById("wilma").onclick = function() {
alert("wilma"); };
}
</script>
</head>
<body onload="init();">
<form id="test" action="" method="post">
<table id="wilma">
<tr><td>&nbsp;</td></tr>
<tr><td><input type="text" name="fred" id="fred"
value="testing"></td></tr> <tr><td>&nbsp;</td></tr>
</table>
</form>
</body>
</html>


<script>
var z=true
function init() {
document.getElementById("fred").onclick =
function() { alert("fred");z=false };
document.getElementById("wilma").onclick =
function() { if(z)alert("wilma");z=true };
}
</script>

--
Evertjan.
The Netherlands.
(Please change the x'es to dots in my emailaddress)
Jul 20 '05 #2
Evertjan. wrote:
<script>
var z=true
function init() {
document.getElementById("fred").onclick =
function() { alert("fred");z=false };
document.getElementById("wilma").onclick =
function() { if(z)alert("wilma");z=true };
}
</script>


Trust me to be thinking about a complex solution when an idiotically
simple one will do!!

I'll crawl under my rock again!

Ian
Jul 20 '05 #3
Another more direct way to do this might be to update Fred's onclick
assignment like so:

document.getElementById("fred").onclick = function() { alert("fred");
window.event.cancelBubble = true; };

Note that this syntax is IE-specific. Netscape 6 and 7 can do something
similar, but the syntax is different.

OTOH, what Evertjan suggested will likely work just as well. :-)

- Tom Kiefer
thogek @ earthlink . net
"Ian Richardson" <za*****@chaos.org.uk> wrote in message
news:c0*************@ID-99375.news.uni-berlin.de...
I have some example code below where, when I click on the background of
the table I want one thing to happen (wilma), and when I click on the
text box I want one different thing to happen (fred).

...but when I click on the text box, both happen (fred, then wilma). I'm
guessing this is to do with event bubbling but I could be thoroughly
mistaken. Anyway, how can I stop it so when I click on the text box only
fred occurs?

<html>
<head>
<style>
table#wilma {
border-color: green;
border-style: solid;
border-width: 2px;
}
</style>
<script>
function init() {
document.getElementById("fred").onclick = function() { alert("fred"); };
document.getElementById("wilma").onclick = function() { alert("wilma"); };
}
</script>
</head>
<body onload="init();">
<form id="test" action="" method="post">
<table id="wilma">
<tr><td>&nbsp;</td></tr>
<tr><td><input type="text" name="fred" id="fred" value="testing"></td></tr> <tr><td>&nbsp;</td></tr>
</table>
</form>
</body>
</html>
TIA

Ian

Jul 20 '05 #4

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

2
by: engsol | last post by:
I'm using Python to parse a bunch of s/w test files and make csv files for later report generation by MS ACCESS....(my boss loves the quick turn-around compared to C). Each log file may contain one...
1
by: Luca | last post by:
Hi. I need to stop mssql service via command row. How can I do? Tnk, Luca
8
by: Eric Osman | last post by:
My javascript program has reason to want to stop. For example, function A has 5 lines, the second of which calls function B, which has 5 lines, the first of which calls function C. But...
5
by: Paul O. Morris | last post by:
Is there a script that I can run to stop a particular SQL server service on Win2003 server? I'm looking for a similar script to restart that service as well. Thanks.
2
by: Adrian MacNair | last post by:
Hi I need some help if anyone can understand my crap javascript. The problem is that after the slideshow ends (reaches the end of array) it should stop, but the timeout doesn't clear and I can see...
7
by: Gayathri | last post by:
Is there anyway to disable the stop button in IE 6? Without doing "Opening in new window and toolbar is set to no" what will document.onstop help in?? I need to capture the browser stop...
2
by: Prasad | last post by:
Hi, I am writing a service which takes a long time to stop after the OnStop call is given by the Services Snap-in. The problem is I cannot cut down on the time that it takes to Stop. The Service...
8
by: Matt Theule | last post by:
While stepping through an ASP.NET project, I found that data was being inserted into my database even though I was not stepping through the code that inserted the data. I have a single page with...
7
by: shai | last post by:
I am working at .net 1.1, writing in c#. I have windows service with a COM object. Every unexpected time The COM object throw an error that make my service get stuck (do not respond). I can catch...
0
by: mattcfisher | last post by:
Hi, I have two windows services running together. One is the main program, and one is an "updater" wrapper for the main. The updater service starts and stops the main one (as in you should never...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
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
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
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...

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.