473,378 Members | 1,037 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,378 software developers and data experts.

Passing back an element that's been OnClicked

If I surround a number of form elements with a <DIVtag and put an
OnClick in the DIV tag, if I click on any of the form elements
(checkboxes and radios, in this instance) inside the DIV, is there a
way of telling which element has been clicked on/checked/unchecked,
short of putting an onclick into each individual element? Is there a
property that can be read that stores what was last Clicked on? Even
just the NAME or ID?

Aug 17 '06 #1
3 1735

st*****@hotmail.com wrote:
If I surround a number of form elements with a <DIVtag and put an
OnClick in the DIV tag, if I click on any of the form elements
(checkboxes and radios, in this instance) inside the DIV, is there a
way of telling which element has been clicked on/checked/unchecked,
short of putting an onclick into each individual element? Is there a
property that can be read that stores what was last Clicked on? Even
just the NAME or ID?
The event object associated with the onclick has either a srcElement
(IE) or target (W3C) property that is a reference to the element that
originally fired the onclick event:

<script type="text/javascript">

function foo(e){
var tgt = e.target || e.srcElement;
alert('You clicked on a ' + tgt.nodeName);
}

</script>
<div style="width: 15em; height: 5em; background-color: #def;"
onclick="foo(event);">
<p>Here is a paragraph <span style="color: blue;">And
here is a span <b>bold</b></span></p>
</div>
--
Rob

Aug 17 '06 #2
Thank you for your reply. I see that srcElement is the property I
want, but how do I get your function to return the NAME or ID of the
element (checkbox, radio etc) that I clicked on? I tried tgt.Name but
that doesn't work.

Or better still, where can I find on the web a list of properties I can
read from srcElement? I can see nodeName is one - how many others are
there?

Aug 18 '06 #3

It's okay - I figured it out. I should have used all lower case for
the element's property, so "event.srcElement.name" will give me the
name, "event.srcElement.value" the value, etc.

Thanks for your help. This information will help me a lot, and save
loads of time when doing the validation for forms.

Aug 18 '06 #4

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

Similar topics

2
by: csx | last post by:
Hi all, Here's a simple problem I'm having problems with. How do I pass an array element to a function. For instance, values = new values(1, 1,'A',0); values = new values(2, 2,'B',1);...
58
by: jr | last post by:
Sorry for this very dumb question, but I've clearly got a long way to go! Can someone please help me pass an array into a function. Here's a starting point. void TheMainFunc() { // Body of...
2
by: Morgan | last post by:
Thanks to all of you because I solved the problem related with my previous post. I simply made confusion with pointers to pointers and then succeeded passing the reference to the first element...
4
by: dogalacar | last post by:
Hi All, I am trying to pass array of structures from a C dll to C# as msdn sample does(outarrayofstructs sample) but PtrToStructure function gives error : --> "structure must not be a value...
22
by: Arne | last post by:
How do I pass a dataset to a webservices? I need to submit a shoppingcart from a pocket PC to a webservice. What is the right datatype? II have tried dataset as a datatype, but I can't get it to...
11
by: John Pass | last post by:
Hi, In the attached example, I do understand that the references are not changed if an array is passed by Val. What I do not understand is the result of line 99 (If one can find this by line...
3
by: Andy | last post by:
Hi, Have just found a bug in Netscape for some of my Javascript code - works ok in Internet Explorer. Given the following form element: <input type="text" compulsory = "yes" name="an_el"> ...
2
by: Jeff Calico | last post by:
Hello everyone I have sucessfully implemented a SAX filter to take a large XML data file, and strip it down to its essential elements, and then pass that on to an XSL transformer. (A bare bones...
20
by: MartinRinehart | last post by:
Is the following correct? x = "some string" x is a reference to "some string" foo(x) Reference is passed to function.
1
by: CloudSolutions | last post by:
Introduction: For many beginners and individual users, requiring a credit card and email registration may pose a barrier when starting to use cloud servers. However, some cloud server providers now...
0
by: Faith0G | last post by:
I am starting a new it consulting business and it's been a while since I setup a new website. Is wordpress still the best web based software for hosting a 5 page website? The webpages will be...
0
by: taylorcarr | last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
0
by: aa123db | last post by:
Variable and constants Use var or let for variables and const fror constants. Var foo ='bar'; Let foo ='bar';const baz ='bar'; Functions function $name$ ($parameters$) { } ...
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
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
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...

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.