473,839 Members | 1,455 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

Identifying the element clicked

Hello,

Here is my problem: I have a site that uses urls of this format to
submit forms:

<a id="1_1_2_0"
href="Javascrip t:if(validate)s ubmitForm(...)" >Submit</a>
I'm just a third-party programmer, I have no control over this
format. I am tasked with writing a function that will be able to fire
on the click and within that function I need to identify exactly which
submission was fired. The function will run inside the validation
code.

When called within the href, 'this' seems to refer to the entire
window, not to the anchor element. For example:

<script>

function list(obj){
var text = "";
for (n in obj){
text += n + "\n";
}
alert(text);
}

</script>
<a id="1_1_2_0"
href="Javascrip t:if(validate)l ist(this);submi tForm(...)">Sub mit</a>

Thus, I can't use the ordinary method of 'this.id' which would return
the link id value.

Is there some way within that href of dynamically determining which
anchor is being clicked? I can't see it.

thanks.

mp

--
cat: $HOME/.signature: No such file or directory
Feb 14 '08 #1
3 2333
On 14 æÅ×, 12:02, Michael Powe <michael+g...@t rollope.orgwrot e:
Hello,

Here is my problem: I have a site that uses urls of this format to
submit forms:

<a id="1_1_2_0"
href="Javascrip t:if(validate)s ubmitForm(...)" >Submit</a>

I'm just a third-party programmer, I have no control over this
format. I am tasked with writing a function that will be able to fire
on the click and within that function I need to identify exactly which
submission was fired. The function will run inside the validation
code.

When called within the href, 'this' seems to refer to the entire
window, not to the anchor element. For example:

<script>

function list(obj){
var text = "";
for (n in obj){
text += n + "\n";
}
alert(text);

}

</script>
<a id="1_1_2_0"
href="Javascrip t:if(validate)l ist(this);submi tForm(...)">Sub mit</a>

Thus, I can't use the ordinary method of 'this.id' which would return
the link id value.

Is there some way within that href of dynamically determining which
anchor is being clicked? I can't see it.

thanks.

mp

--
cat: $HOME/.signature: No such file or directory
Hi. See this.
function list(aEvt){
var element = typeof aEvt.which=="un defined" ?
aEvt.srcElement : aEvt.target;
alert(element.h ref);
return false;
}

<a href="tes.html" onclick="return list(event);">t est</a>
Feb 14 '08 #2
On Feb 14, 10:27 am, Georgi Naumov wrote:
<snip>
function list(aEvt){
var element = typeof aEvt.which=="un defined" ?
aEvt.srcElement : aEvt.target;
Why the unfounded inference from the type of a - which - property of
an event object to the use of its - srcElement - or - target -
properties? Surly the trueness of the values of the - srcElement - and/
or - target - properties would have a reliable and direct relationship
with the viability of employing them?

alert(element.h ref);
return false;
}

<a href="tes.html" onclick="return list(event);">t est</a>
In the - onclick - attribute code of an A element the - this - keyword
can reliably be expected to refer to the element, making your - list -
function needlessly complex in context. The OP's problem is that he is
attempting to use the HREF attribute to execute code and code from
that source is executed in the global context and there the - this -
keyword refers to the window/global object. The solution to that
problem is to abandon the use of the HREF to execute code and instead
use an - onclick - attribute, especially as, to the best of my
recollection of that distant a past, the only browsers where executing
code in an HREF was supported for A elements and an - onclick -
handler was not were Netscape <=2, and nobody worries about those
browsers any more.
Feb 14 '08 #3
Michael Powe wrote:
Here is my problem: I have a site that uses urls of this format to
submit forms:

<a id="1_1_2_0"
href="Javascrip t:if(validate)s ubmitForm(...)" >Submit</a>
I'm just a third-party programmer, I have no control over this
format.
You would be well-advised to lose the bad framework that generates this
inaccessible code element then. Proper validating and submitting forms
is done as follows:

<form ... onsubmit="retur n validate;">
...
<input type="submit" ...>
or
<input type="image" ...>
</form>

Usually `validate' would be `validate()', calling a validation function that
returns `true' on success if scripting is supported, submitting the form,
`false' otherwise. If there was no scripting support, the `onsubmit'
attribute would be ignored; that also emphasizes that you have to do
server-side validation anyway.
PointedEars
--
realism: HTML 4.01 Strict
evangelism: XHTML 1.0 Strict
madness: XHTML 1.1 as application/xhtml+xml
-- Bjoern Hoehrmann
Feb 17 '08 #4

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

Similar topics

4
4764
by: Armando | last post by:
Hey again - I have a bunch of similar controls on a form (A2000), and I'm calling the same code (with an argument as to what was clicked) when any one of them is clicked. I'd like to generalize the code without having to modify EACH one with a self-specific parameter in the call. That is, instead of calling... called_when_clicked ("A1") I just want to run:
4
10915
by: pamelafluente | last post by:
Hello. A question. It is possible to refer to the ID of an element within the element itself? And, if yes, what is the instruction or function. Example. Assume I have this: <div id="Square1" onclick = "Clicked('Square1')"></div> You see the ID of the element "Square1" also appears later on the function invocation "Clicked('Square1')". My question is: can I replace
1
1691
by: daldridge | last post by:
I have a unique-elements/sorting question (who doesn't?), but haven't yet been able to get appropriate template/select/for-each processing working. I don't fully grok the Muenchian technique yet (still an XSLT n00b), but I'm not sure that's the way to go anyway... What I'm trying to accomplish is generation of XML Schema output from a given XML input, with "xs:import" elements in the output with the "namespace" and "schemaLocation"...
6
1822
by: Vortexmind | last post by:
Hi all I was wondering if this is possible in Javascript. I want to make a bookmarklet. When a user launches it, it tells the user to select an element in the page (for example a textarea) with the mouse. When the user clicks on the textarea, my script gets a reference of the element that he clicked so i can operate on it. Is it possibile? Thanks for any input on this, I have some difficulties sorting my ideas out :)
0
9855
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, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main usage, and What is the difference between ONU and Router. Let’s take a closer look ! Part I. Meaning of...
0
9697
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 effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
0
10907
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, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. Here is my compilation command: g++-12 -std=c++20 -Wnarrowing bit_field.cpp Here is the code in...
1
10647
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 Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For most users, this new feature is actually very convenient. If you want to control the update process,...
0
10293
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 protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
0
9426
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, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then launch it, all on its own.... Now, this would greatly impact the work of software developers. The idea...
1
7828
isladogs
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 presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes instead of User Defined Types (UDT). For example, to manage the data in unbound forms. Adolph will...
0
5866
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
3
3133
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 can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating effective websites that not only look great but also perform exceptionally well. In this comprehensive...

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.