Hi I have a simple question. From a click event, how do I find out
what element triggered it? In delphi there was a property called
"sender" which was the sender.
Heres an example of what I'm doing:
jQuery('#buttonA, #buttonB').bind('click', function()
{
if sender is buttonA
do something
else
do something else.
});
I would like it to be the same function just in one part it has to do
one thing if the sender is something otherwise it does something
else. Thanks! 9 1111
On Jun 3, 4:47*pm, oddvark <dgrd...@yahoo.comwrote:
Hi I have a simple question. *From a click event, how do I find out
what element triggered it? *In delphi there was a property called
"sender" which was the sender.
Heres an example of what I'm doing:
* * jQuery('#buttonA, #buttonB').bind('click', function()
* * {
* * * * if sender is buttonA
* * * * * * do something
* * * * else
* * * * * *do something else.
* * });
I would like it to be the same function just in one part it has to do
one thing if the sender is something otherwise it does something
else. *Thanks!
I do not know delphi but this sounds similar:
<body>
<input type="button" id="buttona" name="buttona" value="Button A"
onclick="dosomething(this)">
<input type="button" id="buttonb" name="buttonb" value="Button B"
onclick="dosomething(this)">
<script>
function dosomething(o) {
if(o.id == "buttona") {
do something
} else {
do something else
}
}
</script>
</body>
On Jun 4, 7:47 am, oddvark <dgrd...@yahoo.comwrote:
Hi I have a simple question. From a click event, how do I find out
what element triggered it? In delphi there was a property called
"sender" which was the sender.
Heres an example of what I'm doing:
jQuery('#buttonA, #buttonB').bind('click', function()
If you want information specifically about jQuery, ask in a jQuery
forum. If you want to know how to do it generically using javascript,
then this is the place.
{
if sender is buttonA
do something
else
do something else.
});
I would like it to be the same function just in one part it has to do
one thing if the sender is something otherwise it does something
else.
The event object related to the click event has properties of either
target (W3C event model) or srcElement (IE event model).
There is a good introduction to events at the link below that will
give you enough to get started:
<URL: http://www.quirksmode.org/js/introevents.html >
--
Rob
Unfortunately I cant pass in the object as a parameter to the call.
The click function takes no parameters.
On Jun 3, 3:44 pm, RobG <rg...@iinet.net.auwrote:
On Jun 4, 7:47 am, oddvark <dgrd...@yahoo.comwrote:
Hi I have a simple question. From a click event, how do I find out
what element triggered it? In delphi there was a property called
"sender" which was the sender.
Heres an example of what I'm doing:
jQuery('#buttonA, #buttonB').bind('click', function()
If you want information specifically about jQuery, ask in a jQuery
forum. If you want to know how to do it generically using javascript,
then this is the place.
{
if sender is buttonA
do something
else
do something else.
});
I would like it to be the same function just in one part it has to do
one thing if the sender is something otherwise it does something
else.
The event object related to the click event has properties of either
target (W3C event model) or srcElement (IE event model).
There is a good introduction to events at the link below that will
give you enough to get started:
<URL:http://www.quirksmode.org/js/introevents.html>
--
Rob
Thanks Rob. Let me try the srcElement property.
On Jun 3, 7:46*pm, oddvark <dgrd...@yahoo.comwrote:
On Jun 3, 3:44 pm, RobG <rg...@iinet.net.auwrote:
On Jun 4, 7:47 am, oddvark <dgrd...@yahoo.comwrote:
Hi I have a simple question. *From a click event, how do I find out
what element triggered it? *In delphi there was a property called
"sender" which was the sender.
Heres an example of what I'm doing:
* * jQuery('#buttonA, #buttonB').bind('click', function()
If you want information specifically about jQuery, ask in a jQuery
forum. *If you want to know how to do it generically using javascript,
then this is the place.
* * {
* * * * if sender is buttonA
* * * * * * do something
* * * * else
* * * * * *do something else.
* * });
I would like it to be the same function just in one part it has to do
one thing if the sender is something otherwise it does something
else.
The event object related to the click event has properties of either
target (W3C event model) or srcElement (IE event model).
There is a good introduction to events at the link below that will
give you enough to get started:
<URL:http://www.quirksmode.org/js/introevents.html>
--
Rob
Thanks Rob. *Let me try the srcElement property.- Hide quoted text -
- Show quoted text -
oh, ok try:
<body>
<input type="button" id="buttona" name="buttona" value="Button A"
onclick="dosomething()">
<input type="button" id="buttonb" name="buttonb" value="Button B"
onclick="dosomething()">
<script>
function dosomething() {
if(event.srcElement.id == "buttona") {
do something
} else {
do something else
}
}
</script>
Tue, 3 Jun 2008 15:44:50 -0700 (PDT), /oddvark/:
Hi I have a simple question. From a click event, how do I find out
what element triggered it? In delphi there was a property called
"sender" which was the sender.
Heres an example of what I'm doing:
jQuery('#buttonA, #buttonB').bind('click', function()
{
if sender is buttonA
do something
else
do something else.
});
As others have noted the W3C standard Event [1] interface has a
'target' property. IE's event [2] however doesn't support it but
has a 'srcElement' serving the same purpose. As you seem to use
jQuery you may take a look at its documentation [3]. There you'll
find it normalizes this difference allowing you to use it uniformly.
[1] <http://www.w3.org/TR/DOM-Level-2-Events/events.html#Events-Event>
[2] <http://msdn.microsoft.com/en-us/library/ms535863(VS.85).aspx>
[3] <http://docs.jquery.com/Types#Event>,
<http://docs.jquery.com/Types/Event>
--
Stanimir
Tue, 3 Jun 2008 17:43:39 -0700 (PDT), /oddvark/:
Unfortunately I cant pass in the object as a parameter to the call.
The click function takes no parameters.
You're wrong. Check with your documentation
<http://docs.jquery.com/Events/click#fn>:
Arguments:
fn Function
A function to bind to the click event on each of the matched
elements.
function callback(eventObject) {
this; // dom element
}
--
Stanimir
Thomas 'PointedEars' Lahn wrote:
Lee wrote:
>function dosomething() { if(event.srcElement.id == "buttona") {
This will break with a TypeError in !(MSHTML || Opera) because `event'
cannot be resolved. [...]
Correction: It will be a ReferenceError.
PointedEars
--
var bugRiddenCrashPronePieceOfJunk = (
navigator.userAgent.indexOf('MSIE 5') != -1
&& navigator.userAgent.indexOf('Mac') != -1
) // Plone, register_function.js:16
oddvark escribió:
Hi I have a simple question. From a click event, how do I find out
what element triggered it? In delphi there was a property called
"sender" which was the sender.
Heres an example of what I'm doing:
jQuery('#buttonA, #buttonB').bind('click', function()
{
if sender is buttonA
do something
else
do something else.
});
In jQuery I believe it is:
$(this)
I can't find the exact documentation page but I've seen it in some of
the examples like: http://docs.jquery.com/Events/bind#typedatafn
--
-- http://alvaro.es - Álvaro G. Vicario - Burgos, Spain
-- Mi sitio sobre programación web: http://bits.demogracia.com
-- Mi web de humor al baño María: http://www.demogracia.com
-- This thread has been closed and replies have been disabled. Please start a new discussion. Similar topics
by: Nigel Molesworth |
last post by:
I've Googled, but can't find what I need, perhaps I asking the wrong
question!
I want a "FAQ" page on a web site, I hate those pages that scroll you to
the answer so and I figured that a good...
|
by: new coder |
last post by:
I'm creating a web app in .net 2005, on the form I allow users to do a
search based on the information they selected, then click a button then a
grid is populated. So my question is the person that...
|
by: Csaba Gabor |
last post by:
I feel like it's the twilight zone here as several seemingly trivial
questions are bugging me.
The first of the following three lines is a syntax error, while the
last one is the only one that...
|
by: janetb |
last post by:
Brand new to xml and I'm trying to get Scott Mitchell's rss aggregator example working locally. Basically, involves a frameset with the channels(feeds) in the left frame, a list of items in the...
|
by: Kevin Blount |
last post by:
I'm trying to create a mutli-form page on my website, but having trouble
with the PostBack stuff. And yes, I'm new to C# - my background of 8yrs
is original ASP, and I'm getting easily confused...
|
by: Laharl |
last post by:
I'm working in pyGTK (completely new to it) and I need to display a tic-tac-toe board. It doesn't have to keep track of the game state, just place Xs and Os on click. Unfortunately, I can't get all 9...
|
by: Banibrata Dutta |
last post by:
Hi,
I've gone through the list of "language differences" between 2.3 / 2.4
& 2.5 of CPython. I've spend around 2 weeks now, learning v2.5 of
CPython, and I consider myself still very very...
|
by: Lokean |
last post by:
Sorry for this newbie question, this is not my realm of expertese.
I have searched google, tried several applications that claim they can do this, such as Mapforce, which I found confusing, to...
|
by: Dave |
last post by:
I am new to Visual Web Developer 2005 Expres.
I am using absolute positioning and every time I add a button control to my
web form its width extends all the way to the edge of the page. IOW I...
|
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...
|
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...
|
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...
|
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,...
|
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...
|
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: 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,...
|
by: isladogs |
last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM).
In this session, we are pleased to welcome a new...
|
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...
| |