Tycoon Talk
Become a Big fish!
The number 1 forum for online business!
Post topics, ask questions, share your knowledge.
Tycoon Talk is part of Freelancer.com - find skilled workers online at a fraction of the cost.

JavaScript Forum


You are currently viewing our JavaScript Forum as a guest. Please register to participate.
Login



Reply
Get element location on page
Old 11-28-2008, 01:13 PM Get element location on page
Skilled Talker

Posts: 64
Trades: 0
HTML Code:
<script type="text/javascript">
function d(v){
document.getElementById('dd').innerHTML=v;
}
</script>

<span id="dd">This will change when I click the Input</span>

<form name="form">
<input type="text" name="input" onClick="d(?????);">
</form>
I'm not sure if this is possible but what I want to happen onClick is for the location of the input to appear in the <span> tags.
e.g - document.form.input

I just don't know what to put in the bit I marked ?????. I've tried 'this', 'this.location' and others but I can't seem to get it, is it possible?
Petsmacker is offline
Reply With Quote
View Public Profile
 
 
Register now for full access!
Old 11-28-2008, 01:16 PM Re: Get element location on page
chrishirst's Avatar
Missing! presumed drunk.

Posts: 41,519
Name: Chris Hirst
Location: Blackpool. UK
Trades: 0
this.value
__________________
Chris. ->> Links are advertising NOT optimising!! <<-
A foolish consistency is the hobgoblin of little minds
Thought for today:- I SEO the only industry where all the cowboys are Indians?
chrishirst is online now
Reply With Quote
View Public Profile Visit chrishirst's homepage!
 
Old 11-28-2008, 01:24 PM Re: Get element location on page
Skilled Talker

Posts: 64
Trades: 0
Thanks Chris, but I'm not trying to ascertain the value of the input.
Rather, how if I was trying to pinpoint it in Javascript by writing something like:

document.form.input.value="whatever"

I just want the span to say the above except without the '.value="whatever"' bit.

So if I were to add that function to each of my form elements, the span change would happen with the location changing according to each element.
Petsmacker is offline
Reply With Quote
View Public Profile
 
Old 11-28-2008, 01:38 PM Re: Get element location on page
wayfarer07's Avatar
Poo on You

Latest Blog Post:
Introducing WowWindow
Posts: 3,985
Name: Abel Mohler
Location: Asheville, North Carolina USA
Trades: 0
What in the world do you mean by "location"?
__________________
Join me on
Please login or register to view this content. Registration is FREE
wayfarer07 is offline
Reply With Quote
View Public Profile Visit wayfarer07's homepage!
 
Old 11-28-2008, 01:39 PM Re: Get element location on page
chrishirst's Avatar
Missing! presumed drunk.

Posts: 41,519
Name: Chris Hirst
Location: Blackpool. UK
Trades: 0
Not sure I understand, well I probably do just not sure how YOU want to implement it

because every element can have several references relative to it's parent, grandparent, great-grandparent etc etc.

do you just want to parse out the immediate parentage of the object?
__________________
Chris. ->> Links are advertising NOT optimising!! <<-
A foolish consistency is the hobgoblin of little minds
Thought for today:- I SEO the only industry where all the cowboys are Indians?
chrishirst is online now
Reply With Quote
View Public Profile Visit chrishirst's homepage!
 
Old 11-28-2008, 02:03 PM Re: Get element location on page
Skilled Talker

Posts: 64
Trades: 0
Ok, here's what I'm trying to do or at least what I've done up to this point.

I've got AJAX to dynamically create me a form called 'pageform' within a <div>. Meaning that the form itself was never part of the source code on the original page, rather the form was generated by an external file that validated the PHP and sent via xmlHttp.responseText into the div.

So - I have a form inside a div.
Now I've filled in some details on this form in the div and click 'Send'. Another AJAX function takes over and tries to isolate each of the values I've entered in the form.

The problem arises that as the elements inside the form in the div were not part of the original document, I can't seem to use:
var password=document.pageform.password.value;

The div they're inside is called 'pagediv' the form thats generated is called 'pageform' the input is called 'password'.
So I tried something like this (pretty much knowing it wouldn't work):
var password=document.getElementById('pagediv').passwo rd.value;


So now what I'm asking is if anyone knows how to get the parentage of a form element, no matter where it may be, if its in the original source code, or if it was generated dynamically - so that I know what to put in to isolate the form elements I want in the .js file.

If any of you have any idea how I can get the parentage of the form elements within the div then please let me know. I've looked into layers and Level 1 DOM's but have no idea if I'm on the right track.

Last edited by Petsmacker; 11-28-2008 at 02:04 PM..
Petsmacker is offline
Reply With Quote
View Public Profile
 
Old 11-28-2008, 02:07 PM Re: Get element location on page
chrishirst's Avatar
Missing! presumed drunk.

Posts: 41,519
Name: Chris Hirst
Location: Blackpool. UK
Trades: 0
this.parentNode
__________________
Chris. ->> Links are advertising NOT optimising!! <<-
A foolish consistency is the hobgoblin of little minds
Thought for today:- I SEO the only industry where all the cowboys are Indians?
chrishirst is online now
Reply With Quote
View Public Profile Visit chrishirst's homepage!
 
Old 11-28-2008, 02:11 PM Re: Get element location on page
Skilled Talker

Posts: 64
Trades: 0
The span just outputs: [object HTMLFormElement]
Petsmacker is offline
Reply With Quote
View Public Profile
 
Old 11-28-2008, 03:00 PM Re: Get element location on page
chrishirst's Avatar
Missing! presumed drunk.

Posts: 41,519
Name: Chris Hirst
Location: Blackpool. UK
Trades: 0
Yep it will, because that is what it is, an object. You have to extract the various attributes from the object.

this.parentNode.id
this.parentNode.name
this.parentNode.parentNode to go up the tree one branch

Welcome to Object Oriented Programming
__________________
Chris. ->> Links are advertising NOT optimising!! <<-
A foolish consistency is the hobgoblin of little minds
Thought for today:- I SEO the only industry where all the cowboys are Indians?
chrishirst is online now
Reply With Quote
View Public Profile Visit chrishirst's homepage!
 
Reply     « Reply to Get element location on page
 

Thread Tools Search this Thread
Search this Thread:

Advanced Search

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are Off
Pingbacks are Off
Refbacks are Off





   
RSS Feed  Feeds: RSS   JS   XML
RSS Feed  Feeds for this forum: RSS   JS   XML



Page generated in 0.47671 seconds with 12 queries