473,796 Members | 2,628 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

Call Javascript function in dtree

2 New Member
Hi I am new to Javascript and I want to use dtree but instead of clicking on the nodes for URL I want to call a another javascript function

Is it something to do in order to achieve that? If yes please help me and forgive me for my ignorance

Thank you in advance
Sep 13 '06 #1
10 10399
itKiwi
2 New Member
Is there anybody who can help us on this ? Like pricter, I am a beginner, and do not want to "mess up" dtree, which others say is very well constructed. I have some ideas, for example, if url is blank, do something, or, call a page with the function embedded, but neither of these seems "right".
Thanks.


Hi I am new to Javascript and I want to use dtree but instead of clicking on the nodes for URL I want to call a another javascript function

Is it something to do in order to achieve that? If yes please help me and forgive me for my ignorance

Thank you in advance
Feb 6 '07 #2
acoder
16,027 Recognized Expert Moderator MVP
Welcome to The Scripts.

See the API for dtree. When adding a node, you can specify a url. There, put in your javascript, e.g.
Expand|Select|Wrap|Line Numbers
  1. 'javascript:myfunction();'
Feb 6 '07 #3
itKiwi
2 New Member
Great ! So simple, when you know how. Another lesson learnt; thanks.
Feb 7 '07 #4
acoder
16,027 Recognized Expert Moderator MVP
No problem, glad you got it working.
Feb 8 '07 #5
sovit
1 New Member
hi,
I have to do multiselect in dtree(). At present it supports single select.
Any pointer would be great help.
Thanks,
Sovit
May 25 '07 #6
acoder
16,027 Recognized Expert Moderator MVP
hi,
I have to do multiselect in dtree(). At present it supports single select.
Any pointer would be great help.
Thanks,
Sovit
Welcome to TSDN!

Why would you want a multi-select for a tree menu?
May 26 '07 #7
pacaetano
1 New Member
Hi
I have to do multiselect in dtree(). At present it supports single select.
I need it because i want collect various nodes to an array and send it ot another page, (just the id's of the nodes)
Thanks,
Sep 19 '07 #8
acoder
16,027 Recognized Expert Moderator MVP
Hi
I have to do multiselect in dtree(). At present it supports single select.
I need it because i want collect various nodes to an array and send it ot another page, (just the id's of the nodes)
Thanks,
Welcome to TSDN!

Unless the author has added this ability, you'll probably have to provide this extended functionality yourself.
Sep 21 '07 #9
aitorsol
1 New Member
Aitor Solozabal Merino

Here is a simple modification of dtree.js found on the web to do what you want

dtree.js modification --> dtreecheckbox.j s

Replace this funtion inside the javascript dtree.js file

Expand|Select|Wrap|Line Numbers
  1. // Creates the node icon, url and text
  2. dTree.prototype.node = function(node, nodeId) {
  3.     var str = '<div class="dTreeNode">' + this.indent(node, nodeId);
  4.     if (this.config.useIcons) {
  5.         if (!node.icon) node.icon = (this.root.id == node.pid) ? this.icon.root : ((node._hc) ? this.icon.folder : this.icon.node);
  6.         if (!node.iconOpen) node.iconOpen = (node._hc) ? this.icon.folderOpen : this.icon.node;
  7.         if (this.root.id == node.pid) {
  8.             node.icon = this.icon.root;
  9.             node.iconOpen = this.icon.root;
  10.         }
  11.       //str += '<img id="i' + this.obj + nodeId + '" src="' + ((node._io) ? node.iconOpen : node.icon) + '" alt="" />';
  12.         str += node.title + '<img id="i' + this.obj + nodeId + '" src="' + ((node._io) ? node.iconOpen : node.icon) + '" alt="" />';
  13.     }
  14.     if (node.url) {
  15.         str += '<a id="s' + this.obj + nodeId + '" class="' + ((this.config.useSelection) ? ((node._is ? 'nodeSel' : 'node')) : 'node') + '" href="' + node.url + '"';
  16.         //if (node.title) str += ' title="' + node.title + '"';
  17.         if (node.target) str += ' target="' + node.target + '"';
  18.         if (this.config.useStatusText) str += ' onmouseover="window.status=\'' + node.name + '\';return true;" onmouseout="window.status=\'\';return true;" ';
  19.         if (this.config.useSelection && ((node._hc && this.config.folderLinks) || !node._hc))
  20.             str += ' onclick="javascript: ' + this.obj + '.s(' + nodeId + ');"';
  21.         str += '>';
  22.     }
  23.     else if ((!this.config.folderLinks || !node.url) && node._hc && node.pid != this.root.id)
  24.         str += '<a href="javascript: ' + this.obj + '.o(' + nodeId + ');" class="node">';
  25.     str += node.name;
  26.     if (node.url || ((!this.config.folderLinks || !node.url) && node._hc)) str += '</a>';
  27.     str += '</div>';
  28.     if (node._hc) {
  29.         str += '<div id="d' + this.obj + nodeId + '" class="clip" style="display:' + ((this.root.id == node.pid || node._io) ? 'block' : 'none') + ';">';
  30.         str += this.addNode(node);
  31.         str += '</div>';
  32.     }
  33.     this.aIndent.pop();
  34.     return str;
  35. };
  36.  
sample form to call a program to show a dtree with check box selection:
form_to_call_tr eeview_checkbox .php
[HTML]<?php


?>
<table>
<tr>
<td>
<FORM name = 'form1' method = 'POST' action = ''>
<input type=text name=valor>
</td>
<td>
<input type=button name=open_popup ONCLICK="window .open('treeview _checkbox.php', 'popuppage', 'scrollbars=yes ,resizable=yes, menubar=yes,wid th=400,height=6 00'); " value=" View ">
</td>
</tr>
<tr>
<td>
<INPUT TYPE=SUBMIT VALUE=OK>
</td></tr>
</table>
[/HTML]

program to show a dtree with checkbox:
treeview_checkb ox.php
[HTML]<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
<html>
<head>
<title>Catalo g Tree</title>

<link rel="StyleSheet " href="dtree.css " type="text/css" />
<script type="text/javascript" src="dtreecheck box.js"></script>

</head>

<body>
<div class="dtree">< FORM>
<p><a href="javascrip t: d.openAll();">o pen all</a> | <a href="javascrip t: d.closeAll();"> close all</a></p>
[/HTML][PHP]<?php
function send_query( $db, $link, $sql ) {
$result = false;
if ($GLOBALS['MYSQLPHPEXTENS ION']=="mysqli"){
if ( mysqli_select_d b( $link,$db) ) {
$result = mysqli_query( $link,$sql );
if ( mysqli_errno( $link ) ) {
echo "MySQL error " . mysqli_errno( $link ) . ": " . mysqli_error( $link ) . "\n<br>When executing:<br>\ n$sql\n<br>";
}
} else {
echo "MySQL error " . mysqli_errno( $link ) . ": " . mysqli_error( $link ) . "\n<br>When selecting database $db\n<br>";
}
}else{
if ( mysql_select_db ( $db,$link) ) {
$result = mysql_query( $sql ,$link);
if ( mysql_errno( $link ) ) {
echo "MySQL error " . mysql_errno( $link ) . ": " . mysql_error( $link ) . "\n<br>When executing:<br>\ n$sql\n<br>";
}
} else {
echo "MySQL error " . mysql_errno( $link ) . ": " . mysql_error( $link ) . "\n<br>When selecting database $db\n<br>";
}
}
return $result;
} //end function send_query
function fill_the_tree( $result) {
if ( $result ) {
if ($GLOBALS['MYSQLPHPEXTENS ION']=="mysqli"){
while ( $row = mysqli_fetch_as soc( $result ) ) {
$campo = 1;
while ( list( $k, $v ) = each( $row ) ) {
if ( $campo == 1 ) {
$treeview_cod = $v;
}
if ( $campo == 2 ) {
$treeview_name = $v;
}
if ( $campo == 3 ) {
$treeview_desc = $v;
If ($treeview_desc =="folder") {
$treeview_url=" ";
}else{
$treeview_url=$ treeview_desc." .url";// or .php or .html
}
}
if ( $campo == 4 ) {
$treeview_paren t_cod = $v;
}
$campo++;
} ;
// rellena el arbol con cada fila que se extrae de la tabla tab_treeview
// Node(id, pid, name, url, title, target, icon, iconOpen, open)
?>
d.add(<?= $treeview_cod;? >,<?= $treeview_paren t_cod;?>,'<?= $treeview_name; ?>','<?= $treeview_url;? >','<?= $treeview_desc; ?>');
<?php
}
mysqli_free_res ult( $result );
}else{
while ( $row = mysql_fetch_ass oc( $result ) ) {
$campo = 1;
while ( list( $k, $v ) = each( $row ) ) {
if ( $campo == 1 ) {
$treeview_cod = $v;
}
if ( $campo == 2 ) {
$treeview_name = $v;
}
if ( $campo == 3 ) {
$treeview_desc = $v;
If ($treeview_desc =="folder") {
$treeview_url=" ";
}else{
$treeview_url=$ treeview_desc." .url";// or .php or .html
}
}
if ( $campo == 4 ) {
$treeview_paren t_cod = $v;
}
$campo++;
} ;
// rellena el arbol con cada fila que se extrae de la tabla tab_treeview
// Node(id, pid, name, url, title, target, icon, iconOpen, open)
//echo "d.add(" . $categories['categories_id'] . "," . $categories['parent_id'] . ",'" . addslashes($cat egories['categories_nam e']) . "','', '<input type=checkbox name=categories value=" . $categories['categories_id'] . ">');\n"; //,," . $categories['categories_id'] . ",,,); \n";

echo "d.add(" . $treeview_cod . "," . $treeview_paren t_cod . ",'" . addslashes($tre eview_name) . "','', '<input type=checkbox name=nodes value=" . $treeview_cod . ">');\n"; //,," . $treeview_cod . ",,,); \n";
}
mysql_free_resu lt( $result );
}
}
} //end function fill_the_tree
echo "<script type='text/javascript'>
<!--

d = new dTree('d'); \n
d.add(0,-1,'Datafile Treeview','','' );\n";

$MYSQLPHPEXTENS ION="mysql"; // "mysqli"
$PASSWORD = "lbsb2vb"; // ""
$HOST = "localhost" ; // "localhost"
$USER = "root"; // "aitorsol"
$DATABASE = "test"; // "aitorsol_es_db "
$TABLE = "tab_treevi ew"; // "tab_treevi ew"
if ($GLOBALS['MYSQLPHPEXTENS ION']=="mysqli"){
$LINK = mysqli_connect( $HOST, $USER, $PASSWORD, $DATABASE ) or die ( "No se ha conectado" );
}else{
$LINK = mysql_connect( $HOST, $USER, $PASSWORD, $DATABASE ) or die ( "No se ha conectado" );
}
$QUERY = "select * from `" . $DATABASE . "` . `" . $TABLE . "` limit 0, 5000";
fill_the_tree( send_query( $DATABASE, $LINK, $QUERY ));

?>[/PHP]
[HTML]document.write( d);

//-->
</script>
<INPUT TYPE="BUTTON" onClick="cycleC heckboxes(this. form)" VALUE="OK">
</form>
<script type='text/javascript'>
<!--
function cycleCheckboxes (what) {

window.opener.d ocument.form1.v alor.value="";
for (var i = 0; i<what.elements .length; i++) {
if ((what.elements[i].name.indexOf(' nodes') > -1)) {
if (what.elements[i].checked) {
window.opener.d ocument.form1.v alor.value += what.elements[i].value + ',';
}
}
}
window.close();
}
//-->
</script>
</div>
</body>

</html>
[/HTML]


a sql script to create in a mysql "test" database a table and data needed by the sample utility

Expand|Select|Wrap|Line Numbers
  1. use 'test'
  2.  
  3. drop table if exists `tab_treeview`;
  4. CREATE TABLE `tab_treeview` (
  5.   `treeview_cod` smallint(5) NOT NULL auto_increment,
  6.   `treeview_name` char(25) NOT NULL default '',
  7.   `treeview_desc` char(25) NOT NULL default '',
  8.   `treeview_parent_cod` smallint(5) NOT NULL default '0',
  9.   PRIMARY KEY  (`treeview_cod`)
  10. ) ENGINE=MyISAM;
  11.  
  12. INSERT INTO `tab_treeview` VALUES
  13. (1,'root','expediente',0), 
  14. (2,'parent1','expediente',1),
  15. (3,'parent2','expediente',1),
  16. (4,'parent3','expediente',1),
  17. (5,'child1','carpeta',2),
  18. (6,'child2','carpeta',2),
  19. (7,'grandchild1','documento',5),
  20. (8,'grandchild2','documento',5),
  21. (9,'child3','carpeta',4),
  22. (10,'child4','documento',4),
  23. (11,'grandchild3','subcarpeta',9),
  24. (12,'grandgrandchild1','documento',11),
  25. (13,'grandgrandchild2','documento',11);
Feb 25 '08 #10

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

Similar topics

15
4215
by: chirs | last post by:
I am trying to understand a piece of code. In a javascrpit file, there is a function: function ItemStyle(){ var names=; addProps(this,arguments,names,true); }; In the html file, it calls the function as:
5
2694
by: Sue | last post by:
After finishing up my first quarter JavaScript on 12/12/03, I decided to improve character checking on my project. In my project I only had to do very basic validation. Therefore, I only had one function to verify the name fields, age, email and gender. My question is: if I create a function for each field like the code below, what would be the best way to organize the functions and call them? Would I need one main function and place...
1
5079
by: cheezebeetle | last post by:
ok, so I am having problems passing in an ASPX function into the Javascript in the codebehind page. I am simply using a confirm call which when they press "OK" they call this ASPX function, when they press "Cancel" they call another ASPX function. My code now is: System.Web.HttpContext.Current.Response.Write("<SCRIPT LANGUAGE=""JavaScript"">" & vbCrLf) System.Web.HttpContext.Current.Response.Write("if (confirm('Are you sure you want to...
3
4062
by: JoeK | last post by:
Hey all, I am automating a web page from Visual Foxpro. I can control all the textboxes, radio buttons, and command buttons using syntax such as: oIE.Document.Forms("searchform").Item(<name>).Value = <myvalue> But I cannot control a dropdown with an onchange event. I can set the dropdown's value and selectedIndex, but then calling the onChange() or Click() does not do anything. It only seems to fire the onchange if I
39
6557
by: Randell D. | last post by:
Folks, I'm sure this can be done legally, and not thru tricks of the trade - I hope someone can help. I'm writing a 'tool' (a function) which can be used generically in any of my projects. When it completes, it can call a success, or a failure function. The names of these success, or failure functions will differ, and I'd like to know how I can pass the name of a function to my tool, and how my tool can call the function, using that...
18
43566
by: Chris Ianson | last post by:
Hi geniuses (or is that genii, or genies) The challenge is as above really. I have a page with an iframe in it, and need to call a JS function in the *parent* page, *from* inside the iframe. (It's for Google Maps, but I won't bore you with the complexities of that, as it doesn't affect the question). Mochas kudos to anyone able to solve this widdle.
3
3597
by: KaNos | last post by:
Hi, "robot script pages" are html+javascript pages, can be played in aspx player. So in this tech, robot call aspx player's function (an interface is sheared) and wait a result synchronously with a javascript method. I try it with GetCallbackEventReference but this tech works async. Could I use a javascript function with a sync call ? Thaks for responses,
3
3687
by: Angus | last post by:
I have a web page with a toolbar containing a Save button. The Save button can change contextually to be a Search button in some cases. Hence the button name searchsavechanges. The snippet of html is: <a class="searchsavechanges btn btn3d tbbtn" href="javascript:" style="position:static"> <div id="TBsearchsavechanges">Search</div> </a>
0
10449
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...
0
10217
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that captivates audiences and drives business growth. The Art of Business Website Design Your website is...
0
10003
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
9047
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
7546
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
6785
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert into image. Globals.ThisAddIn.Application.ActiveDocument.Select();...
0
5440
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in the same network. But I'm wondering if it's possible to do the same thing, with 2 Pfsense firewalls...
2
3730
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
3
2924
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.