It appears you have not yet registered with DEVPPL. To register please click here... (it's fast, easy and free!)

Forum

Log In Sponsors
Board index Programming JavaScript Forum

Get div id from div itself

Get div id from div itself

Postby Dantenas on Tue Nov 11, 2008 5:49 pm

There's a click button which triggers js function in div with id content. Is it possible to track that id using triggered function? Please write a sample :wink:
Dantenas
 
Posts: 40
Joined: Sat Sep 06, 2008 4:06 pm

Postby Dantenas on Wed Nov 12, 2008 12:54 pm

Function trigger should look like content('url'); If you don't know how, atleast tell me if it's possible.
Dantenas
 
Posts: 40
Joined: Sat Sep 06, 2008 4:06 pm

Postby flabbyrabbit on Wed Nov 12, 2008 5:31 pm

Im sorry but I don't really understand the original question. Is there any chance of giving an example?

Flabby Rabbit
Image
User avatar
flabbyrabbit
500+ Club
 
Posts: 706
Joined: Thu Jan 25, 2007 1:10 pm
Location: Midlands, England

Postby Dantenas on Thu Nov 13, 2008 1:04 pm

function content(url, id, method)
{
var z = '';
if(method != 'POST' && method != 'GET') method = 'GET';
if(method == 'POST') for(var i = 0; i < document.forms['post'].elements.length; i++) z+=document.forms['post'].elements[i].name+'='+document.forms['post'].elements[i].value+(i + 1 < document.forms['post'].elements.length ? '&' : '');
if(document.getElementById)
{
var x = (window.ActiveXObject) ? new ActiveXObject("Microsoft.XMLHTTP") : new XMLHttpRequest();
}
document.getElementById(id).innerHTML='<div class="loading"></div>';
if (x)
{
x.onreadystatechange = function()
{
if (x.readyState == 4 && x.status == 200)
{
y = document.getElementById(id);
y.innerHTML = x.responseText;
}
}
x.open(method, url, true);
if(method == 'POST') x.setRequestHeader('Content-Type', 'application/x-www-form-urlencoded');
x.send(z);
}
}


Code: Select all
<a href="javascript:void(0)" onclick="content(\'php/content.php?id=register\', \'account\')">fghdfh</a>


I want to make as much simple trigger as pssible. It would be great if I could only type
<a href="javascript:void(0)" onclick="content(\'php/content.php?id=register\')">djdfj</a>
and function itself would get the Id (account) from the div in which this trigger is.
Hope you understand what I need.
Dantenas
 
Posts: 40
Joined: Sat Sep 06, 2008 4:06 pm

Postby flabbyrabbit on Thu Nov 13, 2008 1:41 pm

Well if it was the link its self that had the id it would be simply:
Code: Select all
onclick="content(\'php/content.php?id=register\', this.id)"
I am not sure how to get the id of the containing div, i will keep looking and get back to you as soon as I find something.

Sorry I couldn't be more help,
Flabby Rabbit
Image
User avatar
flabbyrabbit
500+ Club
 
Posts: 706
Joined: Thu Jan 25, 2007 1:10 pm
Location: Midlands, England

Postby flabbyrabbit on Thu Nov 13, 2008 1:49 pm

Oh i've got it :D parentNode.id...a quick example:
Code: Select all
<div id="div1">
<a id="link1" onClick="javascript: alert(parentNode.id);">link</a>
</div>
When you click the link it will show a box saying "div1".

I think this is what you were looking for,
Flabby Rabbit
Image
User avatar
flabbyrabbit
500+ Club
 
Posts: 706
Joined: Thu Jan 25, 2007 1:10 pm
Location: Midlands, England

Postby Dantenas on Thu Nov 13, 2008 2:21 pm

Thanks and one more question. Does the same goes for forms?
Dantenas
 
Posts: 40
Joined: Sat Sep 06, 2008 4:06 pm

Postby flabbyrabbit on Thu Nov 13, 2008 2:22 pm

It should do, I haven't tried it but theres no harm in trying.

Flabby Rabbit
Image
User avatar
flabbyrabbit
500+ Club
 
Posts: 706
Joined: Thu Jan 25, 2007 1:10 pm
Location: Midlands, England

Postby Dantenas on Sun Nov 16, 2008 1:15 pm

How to make empty space in function?
I.e lalala = function (url, id) {...}
and I want to call it like lalala(NULL, 'myfavoriteid');
Null doesnt work, I tried only '', but both of them didn't worked either.
Dantenas
 
Posts: 40
Joined: Sat Sep 06, 2008 4:06 pm

Postby Dantenas on Mon Nov 17, 2008 7:11 pm

Wonder if you understand this time :) If not, please say so :wink:
Dantenas
 
Posts: 40
Joined: Sat Sep 06, 2008 4:06 pm

Next

Who is online

Users browsing this forum: No registered users and 5 guests