By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
437,712 Members | 2,063 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 437,712 IT Pros & Developers. It's quick & easy.

Tree view

Fary4u
100+
P: 273
Hi

i'm trying to do treeview
it's working fine but when some body click on the link1 or link2 when the page open it's bring the same list already open

if possible then the link has file link but at the moment it li options

coding rite here in line 32, 39 or 46

[PHP]
<!DOCTYPE html PUBLIC "-/W3C/DTD XHTML 1.0 Strict/EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
<html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en" lang="en">
<head>
<title>Test</title>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
<style type="text/css">
*{list-style:none;font:12px Tahoma;color:#567;margin:0;}
ul li ul{display:none;margin-left:10px}
ul li.active ul{display:block;}
li{clear:both;float:left;cursor:pointer}
</style>
<script type="text/javascript">
function treeView(event)
{
var target = event.target || window.event.srcElement;
if (target.tagName == 'LI')
{
if (target.className!='active')
{
target.className='active';
}
else
{
target.className='';
}
}
}
</script>
</head>
<body>
<ul onclick="treeView(event)">
<li>link 1
<ul>
<li><a href="dsafa">sublink</a></li>
<li><a href="fdsa23">sublink</a></li>
<li><a href="#">sublink</a></li>
</ul>
</li>
<li>link 2
<ul>
<li><a href="#">sublink</a></li>
<li><a href="#">sublink</a></li>
<li><a href="#">sublink</a></li>
</ul>
</li>
<li>link 3
<ul>
<li><a href="#">sublink</a></li>
<li><a href="#">sublink</a></li>
<li><a href="#">sublink</a></li>
</ul>
</li>
</ul>
</body>
</html>
[/PHP]
Jul 2 '08 #1
Share this Question
Share on Google+
19 Replies


acoder
Expert Mod 15k+
P: 16,027
when some body click on the link1 or link2 when the page open it's bring the same list already open
Could you explain what you mean here? I'm not sure I quite follow what you're saying.
Jul 2 '08 #2

Fary4u
100+
P: 273
Thx for kindly reply

well question is i've got three link like
[PHP]Link 1
Link 2
Link 3[/PHP]in javascript somebody click on Link 1 it bring subnode like

[PHP]
Link 1
Link 1-1
Link 1-2
Link 2
Link 3
[/PHP]

iv'e got the code which works fine but when click on Link 1 it's brings the subnode

but i want same time open a file & also open subnode as well
when the file opening it's automaticaly know which node is selected

i've just paste the code above if u just run the script you get know what i want.

thx in advance
Jul 3 '08 #3

acoder
Expert Mod 15k+
P: 16,027
What file(s) would you like to open? Are you looking to download a file or do you mean opening a page?
Jul 3 '08 #4

Fary4u
100+
P: 273
Hi

actually i'm working on asp with database connectivity
& search a result from database & opening a new page & but it's gonna check if link 1 clicked then it's automatically open's subnode as well on the same time

is that possible in this coding which is above ?
Jul 3 '08 #5

acoder
Expert Mod 15k+
P: 16,027
In that case, pass the li id to the page that you're linking to and in your ASP code, if an id is passed, set the li class to active inline. Alternatively, you could use JavaScript, e.g. set/retrieve cookies, but that would show up after page load.
Jul 3 '08 #6

Fary4u
100+
P: 273
is it the best way to do it in asp or javascript ?

could u plz give me some exapmle ? i'm not quite sure ?

thx
Jul 3 '08 #7

acoder
Expert Mod 15k+
P: 16,027
That depends on what you're most comfortable with and what suits your needs. Could there be a possibility that a user does not have JavaScript enabled? Do you need instant interactivity? If you decide to go with the ASP approach, ask in the ASP forum. If not, I can give you some tips.
Jul 3 '08 #8

Fary4u
100+
P: 273
Thx for reply

yes u absoluty right i just wondering if you could sort my programming coz they way you explain me i'm trying 2 do work but giving error could you plz give some time to sort my progrmming out the way you told me ?

look forward to see your reply

Best Regards
Fary
Jul 4 '08 #9

acoder
Expert Mod 15k+
P: 16,027
What error message do you get? Can you post the code that you've tried?
Jul 4 '08 #10

Fary4u
100+
P: 273
[PHP]
<!DOCTYPE html PUBLIC "-/W3C/DTD XHTML 1.0 Strict/EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
<html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en" lang="en">
<head>
<title>Test</title>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
<style type="text/css">
*{list-style:none;font:12px Tahoma;color:#567;margin:0;}
ul li ul{display:none;margin-left:10px}
ul li.active ul{display:block;}
li{clear:both;float:left;cursor:pointer}
</style>
<script type="text/javascript">
function treeView(event)
{
var target = event.target || window.event.srcElement;
if (target.tagName == 'LI')
{
if (target.className!='active')
{
target.className='active';
}
else
{
target.className='';
}
}
}
</script>
</head>
<body>
<ul onclick="treeView(event)">
<li><a herf="open_page_&_subnode.htm">link 1</a>
<ul>
<li><a href="subnode1.htm">sublink1</a></li>
<li><a href="subnode2.htm">sublink2</a></li>
<li><a href="#">sublink</a></li>
</ul>
</li>
<li>link 2
<ul>
<li><a href="#">sublink</a></li>
<li><a href="#">sublink</a></li>
<li><a href="#">sublink</a></li>
</ul>
</li>
<li>link 3
<ul>
<li><a href="#">sublink</a></li>
<li><a href="#">sublink</a></li>
<li><a href="#">sublink</a></li>
</ul>
</li>
</ul>
</body>
</html>
[/PHP]
Jul 7 '08 #11

acoder
Expert Mod 15k+
P: 16,027
"herf" should be "href". What's the error message?
Jul 7 '08 #12

Fary4u
100+
P: 273
actually i'm just explain things
it's the codeing technique like opening file with subnode nothing else

I WANT OPEN NEW PAGE & SUBNODE ON THE SAME TIME

that's the same code i've upload 1st time
plz try to understand the actual scenario
Jul 7 '08 #13

acoder
Expert Mod 15k+
P: 16,027
The problem here is that the link will open in the same window, so the tree will not open up. The link will be followed instead. Will the linked page also show the same tree that you want opened?
Jul 7 '08 #14

Fary4u
100+
P: 273
Thank so much for corporation & reply

Yes you right it's not possible but if to passing values & open subnode with to judge the value ?

is it possible ? any example ?
Jul 9 '08 #15

acoder
Expert Mod 15k+
P: 16,027
I'm sorry, but I'm not sure what you mean by this:
if to passing values & open subnode with to judge the value ?
Do you mean passing the value in the URL to open the node in the linked page?
Jul 9 '08 #16

Fary4u
100+
P: 273
YES you almost know what i'm trying to do.
Jul 9 '08 #17

acoder
Expert Mod 15k+
P: 16,027
OK, what you would need to do is pass some info. in the URL, e.g. "open_page_and_node.asp#link1". Then, either use ASP code to have the li items "block" by default or use JavaScript to open the subnode onload. Call a function onload which checks location.hash. If it's not empty, take the hash value and use it as an id, e.g. "link1". For this to work, you will need to give each list item an ID. Then use document.getElementById() to access the element and set the class to "active".

Alternatively, use cookies whenever a subnode is opened and check for cookies on the next page.
Jul 9 '08 #18

Fary4u
100+
P: 273
Thanks i'm gonna try this & i've got the idea who this gonna work

one more time thx for your concern
Jul 9 '08 #19

acoder
Expert Mod 15k+
P: 16,027
No problem. Let us know how you manage.
Jul 9 '08 #20

Post your reply

Sign in to post your reply or Sign up for a free account.