Problem with attachEvent

hi,
I’m new user;
I try to display files when I click on items of my tree.
Here is my ccode :
page connector.php :

$treeConn->render_sql("SELECT id_docs,title_docs,ref_id,file_upload FROM docs ORDER BY ref_id ASC","id_docs","title_docs,file_upload","","ref_id");

Field “file_upload” contains the names of the files.
Page tree.php :

tree.attachEvent("onClick", function(id) {document.location.href="../works/docs_upld/"+file_upload;});

…but nothing happens, just a blank page : the ‘file_upload’ variable is empty.
Thank you for your help.

is the “file_upload” variable defined somewhere on your client-side?

Hello Sematik,
thanks for reply.
Sorry but i’m newbie and I just don’t know how to define it.
Can you tell me how ?
I thought that i could get ‘file_upload’ like I can get ‘id’.

I have tested this code :

<script type="text/javascript" charset="utf-8"> tree=new dhtmlXTreeObject("treebox_tree","100%","100%",0); tree.setImagePath("dhtmlxTree/dhtmlxTree/codebase/imgs/csh_bluebooks/"); tree.enableTreeImages(false); tree.enableHighlighting(true); tree.loadXML("dhtmlxTree/dhtmlxConnector/connector.php?connector=true"); tree.attachEvent("onClick",function(id){ var file_upload = '<?php echo $item; ?>'; alert(file_upload); document.location.href = "../works/docs_upld/"+file_upload; }); </script>

And my connector.php :

$treeConn = new TreeConnector($res); // connector object; parameters: db connection and the type of the using db function custom_format($item){ $item->set_userdata("file_upload", $item->get_value("file_upload"));} $treeConn->render_sql("SELECT id_docs,title_docs,ref_id,file_upload FROM docs ORDER BY ref_id ASC","id_docs","title_docs,file_upload","","ref_id");// data configuration

But it doesn’t work.
Alert is empty and so the page…
Thanks for your help !

Your “connector.php” returns the generated xml file for your dhtmlxGrid.
Could you please, clarify what your “file_upload” variable should return.
As you may get the userdata for your grid/row on client-side using the API:
docs.dhtmlx.com/grid__userdata.html#userdata

oups ! set_userdata seems the wrong way…

To answer your question : my “file_upload” variable should return the names of the files (i.e. : numeros.pdf)

To be more clear :
My database stocks folders and files names :

"id_docs";"ref_id";"title_docs";"file_upload"; "751";"0";"0";"Consignes obligatoires";; "1";"751";"Documents de référence";; "305";"1";"Consignes générales de sécurité";; "747";"305";"Numeros urgences";"numeros.pdf"; "754";"0";"Procédures";; "8";"754";"Ressources humaines";; "293";"8";"Gestion de la formation";; "325";"293";"Demande de formation";"demande_formation.pdf";

My tree displays these folders and files names (files are stocked in “…/works/docs_upld/”).

Finally I just want :

  1. to open the file when I click on the file name in my tree (i.e. : when I click on “numeros urgence” it opens the file “numeros.pdf”).
  2. and to opens nothing when it’s a parent with child (folder) (i.e. “Procédures”).

Thank you for your patience :slight_smile: