passing variables from Grid to pop form?

I am new at learning DHTLX. I was following the “Building Application” Step-by-Step. So far so good.

Here is my problem.

I have a Master Grid (Dentists) which connects with a detail form on row selection. It also pulls up a grid with all notes associated with that selected row. All is working. :smiley:

However I have a Toolbar button on the Notes Grid that when clicked opens a Form to add a new note. I can’t figure out how to pass the userid (UID) for the selected row (Dentists Grid) to the form so that when it saves, it adds UID as a field into the notes table.

Here is the code:

The work in process is at adsmidwest.com/admin

ADSMIDWEST - Admin Dentists
<!-- dhtmlx.css contains styles definitions for all included components -->
<link rel="STYLESHEET" type="text/css" href="codebase/dhtmlx.css" />
<link rel="stylesheet" type="text/css" href="codebase/skins/dhtmlxwindows_dhx_skyblue.css" />

<style>
    /*these styles allow dhtmlxLayout to work in fullscreen mode in different browsers correctly*/
    html, body {
       width: 100%;
       height: 100%;
       margin: 0px;
       overflow: hidden;
       background-color:white;
    }
</style>

<script type="text/javascript">
   var layout,menu,toolbarDentist,toolbarSales,grid_dentists,contactForm;
       dhtmlx.image_path='./codebase/imgs/';
       dhtmlxEvent(window,"load",function(){

			var main_layout = new dhtmlXLayoutObject(document.body, '1C');
			main_layout.cont.obj._offsetTop = 0;
			main_layout.cont.obj._offsetLeft = 20;
			main_layout.cont.obj._offsetWidth = -40;
			// main_layout.cont.obj._offsetHeight = -30;
			main_layout.setSizes();
				
			menu = main_layout.attachMenu();
            menu.setIconsPath("images/");
            menu.loadXML("/admin/xml/menu.xml");

			var a = main_layout.cells('a');
			var tabbar_main = a.attachTabbar();
			tabbar_main.addTab('tab_dentists','Dentists','');
			tabbar_main.addTab('tab_Sales','Recent Sales','');

			var tab_dentists = tabbar_main.cells('tab_dentists');
			tabbar_main.setTabActive('tab_dentists');
			var layout_dentists = tab_dentists.attachLayout('3L');
		
			var cell_dentist_grid = layout_dentists.cells('a');
			cell_dentist_grid.setText('Dentists');
			
		
			var grid_dentists = cell_dentist_grid.attachGrid();
			grid_dentists.setIconsPath('./codebase/imgs/');

			
					grid_dentists.setHeader("Last Name,First Name,Email,City,State,DOB,Active");
					grid_dentists.setInitWidths("100,100,*,150,50,80,80");
					grid_dentists.setColAlign("left,left,left,left,center,left,center");
					grid_dentists.setColTypes("ro,ro,ro,ro,ro,ro,ch");
					grid_dentists.setColSorting("str,str,str,str,str,date");
					grid_dentists.init();
					grid_dentists.enableSmartRendering(true, 100)						
					grid_dentists.load("xml/contacts.php");
					grid_dentists.attachHeader("#text_filter,#text_filter,#text_filter,#text_filter,#select_filter,#text_filter");
			
			var str = [
                { type:"settings" , labelWidth:80, inputWidth:100, position:"absolute",   },
                { type:"input" , name:"firstname", label:"First Name", labelWidth:150, required:true, labelLeft:20, labelTop:20, inputLeft:100, inputTop:20  },
                { type:"input" , name:"lastname", label:"Last Name", labelWidth:150, required:true, labelLeft:220, labelTop:20, inputLeft:300, inputTop:20  },
                { type:"input" , name:"sur", label:"Surname", labelWidth:55, inputWidth:35, labelLeft:420, labelTop:20, inputLeft:480, inputTop:20  },
                { type:"radio" , name:"dr", label:"DDS", checked:"1", value:"DDS", labelWidth:40, labelAlign:"left", labelLeft:540, labelTop:20, inputLeft:580, inputTop:20  },
                { type:"radio" , name:"dr", label:"DMD", value:"DMD", labelWidth:45, labelAlign:"left", labelLeft:610, labelTop:20, inputLeft:640, inputTop:20  },
				{ type:"input" , name:"address", label:"Address", labelWidth:300, inputWidth:300, labelLeft:38, labelTop:60, inputLeft:100, inputTop:60  },
				{ type:"input" , name:"city", label:"City", labelWidth:150, inputWidth:120, labelLeft:60, labelTop:100, inputLeft:100, inputTop:100  },
				{ type:"input" , name:"state", label:"State", labelWidth:50, inputWidth:20, labelLeft:230, labelTop:100, inputLeft:270, inputTop:100  },
				{ type:"input" , name:"zipcode", label:"Zipcode", labelWidth:50, inputWidth:70, labelLeft:310, labelTop:100, inputLeft:360, inputTop:100  },
				{ type:"input" , name:"dob", label:"DOB", labelWidth:50, inputWidth:70, labelLeft:442, labelTop:60, inputLeft:480, inputTop:60  },
            ];				
			
			var cell_dentists_form = layout_dentists.cells('b');
			cell_dentists_form.setText('Contact Info');
			var form_contact_info = cell_dentists_form.attachForm(str);
			
		
			var notes = layout_dentists.cells('c');
			notes.setText('Notes');
			var grid_notes = notes.attachGrid();
			grid_notes.setIconsPath('./codebase/imgs/');
			
			grid_notes.setIconsPath("images/");
            grid_notes.setHeader("ID,UID,Stamp,Type,Note");
            grid_notes.setInitWidths("50,50,120,40,*");
            grid_notes.setColAlign("center,center,left,center,left");
            grid_notes.setColTypes("ro,ro,ro,img,ed");
            grid_notes.setColSorting("int,int,date,str");
            grid_notes.init();
			
			// on row select from Dentist Grid 
			grid_dentists.attachEvent("onRowSelect", function(rID,cInd){
             	form_contact_info.load("/admin/xml/contact_details.php?id="+rID);
				
				grid_notes.clearAll();
                grid_notes.load("/admin/xml/notes.php?uid="+rID);
				notes.showToolbar()
            })
			
	var tab_Sales = tabbar_main.cells('tab_Sales');
	var grid_sales = tab_Sales.attachGrid();
	grid_sales.setIconsPath('./codebase/imgs/');
	
	grid_sales.setHeader("Broker,Buyer,Seller,City,State,Date");
	grid_sales.setInitWidths("60,250,250,100,80,*");
	grid_sales.setColAlign("left,left,left,left,center,left");
	grid_sales.setColTypes("co,ed,ed,ed,co,ro");
	grid_sales.setColSorting("str,str,str,str,str,date");
	grid_sales.init();
	grid_sales.load('/admin/xml/sales.php');
	
	// TOOLBARS
	toolbarDentist = cell_dentist_grid.attachToolbar();
    toolbarDentist.setIconsPath("images/");
    toolbarDentist.loadXML("/admin/xml/toolbar.xml");
	
	toolbarSales = tab_Sales.attachToolbar();
	toolbarSales.setIconsPath("images/");
	toolbarSales.loadXML("/admin/xml/toolbar_sales.xml");
	
	toolbarNotes = notes.attachToolbar();
	toolbarNotes.setIconsPath("images/");
	toolbarNotes.loadXML("/admin/xml/toolbar_notes.xml");
	notes.hideToolbar();

	
	// EVENTS
	 toolbarDentist.attachEvent("onclick",function(id){
			if(id=="newContact"){
				  //open popup window
				  var popupWindow = main_layout.dhxWins.createWindow("newcontact_win", 0, 0, 400, 600);
				  popupWindow.center();
				  popupWindow.setText("New Contact");
				  //add form
				  var newContactForm = popupWindow.attachForm();
				  newContactForm.loadStruct("/admin/xml/form.xml?i=2345678");
				  var dpfs = new dataProcessor("/admin/xml/contact_details.php");
				  dpfs.init(newContactForm);
				  newContactForm.attachEvent("onButtonClick", function(name, command){
					  dpfs.sendData();
				  });
				  dpfs.attachEvent("onAfterUpdate",function(sid,action,tid,xml_node){
					   if(action=="inserted"){
						  dpg.ignore(function(){
							  grid_dentists.addRow(tid,[newContactForm.getItemValue("firstname"),newContactForm.getItemValue("lastname"),newContactForm.getItemValue("email"),
							  newContactForm.getItemValue("city"),newContactForm.getItemValue("state"),newContactForm.getItemValue("dob")],0)
						  });
						  grid_dentists.selectRowById(tid,false,false,true);
						  popupWindow.close();
					  }
				  })
				}
          });


var dpg = new dataProcessor("/admin/xml/sales.php");
dpg.init(grid_sales);


toolbarSales.attachEvent("onclick",function(id){
	if(id=="newSale"){
	  //open popup window
	  var popupWindow = main_layout.dhxWins.createWindow("newsale_win", 0, 0, 420, 230);
	  popupWindow.center();
	  popupWindow.setText("New Sale");
	  //add form
	  var newSaleForm = popupWindow.attachForm();
	  newSaleForm.loadStruct("/admin/xml/form_sales.xml?i=2345678");
	  var dpfs = new dataProcessor("/admin/xml/sales_details.php");
	  dpfs.init(newSaleForm);
	  newSaleForm.attachEvent("onButtonClick", function(name, command){
		  dpfs.sendData();
	  });
	  dpfs.attachEvent("onAfterUpdate",function(sid,action,tid,xml_node){
		   if(action=="inserted"){
			  dpg.ignore(function(){
				  grid_sales.addRow(tid,[newSaleForm.getItemValue("broker"),newSaleForm.getItemValue("buyer"),newSaleForm.getItemValue("seller"),
				  newSaleForm.getItemValue("city"), newSaleForm.getItemValue("state"),newSaleForm.getItemValue("date")],0)
			  });
			  grid_sales.selectRowById(tid,false,false,true);
			  popupWindow.close();
		  }
	  })
	}
  });
  
	  
  toolbarSales.attachEvent("onclick",function(id){
            if(id=="delSale"){
               var rowId = grid_sales.getSelectedRowId();
               if(rowId!=null){
                  var selectedIndex = grid_sales.getRowIndex(rowId)
                  grid_sales.deleteRow(rowId);
                  if(selectedIndex!=(grid_sales.getRowsNum()-1)){
                     grid_sales.selectRow(selectedIndex+1,true);
                  }
                  else{
                     grid_sales.selectRow(selectedIndex-1,true)
                  }
                }
            }
        });
  
  	
	var dpg = new dataProcessor("/admin/xml/notes.php");
    dpg.init(grid_notes);
	
	toolbarNotes.attachEvent("onclick",function(id){
					if(id=="newNote"){
					  //open popup window
					  var popupWindow = main_layout.dhxWins.createWindow("newnote_win", 0, 0, 500, 270);
					  popupWindow.center();
					  popupWindow.setText("New Note");
					  //add form
					  var newNoteForm = popupWindow.attachForm();
					  newNoteForm.loadStruct("/admin/xml/note.xml?i=2345678");
					  var dpfs = new dataProcessor("/admin/xml/note_detail.php?uid="+rID);
					  dpfs.init(newNoteForm);
					  newNoteForm.attachEvent("onButtonClick", function(name, command){
						  dpfs.sendData();
					  });
					  dpfs.attachEvent("onAfterUpdate",function(sid,action,tid,xml_node){
						   if(action=="inserted"){
							  dpg.ignore(function(){
								  grid_notes.addRow(tid,[rID,newNoteForm.getItemValue("type"),newNoteForm.getItemValue("note_text")],0)
							  });
							  grid_notes.selectRowById(tid,false,false,true);
							  popupWindow.close();
						  }
					  })
					}
				  });
				  
					  
				  toolbarNotes.attachEvent("onclick",function(id){
							if(id=="delNote"){
							   var rowId = grid_notes.getSelectedRowId();
							   if(rowId!=null){
								  var selectedIndex = grid_notes.getRowIndex(rowId)
								  grid_notes.deleteRow(rowId);
								  if(selectedIndex!=(grid_notes.getRowsNum()-1)){
									 grid_notes.selectRow(selectedIndex+1,true);
								  }
								  else{
									 grid_notes.selectRow(selectedIndex-1,true)
								  }
								}
							}
						});

  
  // end of code

});

</script>

<script type="text/javascript" src="/admin/includes/menu.js" ></script>

You may try to use the getSelectedRowId() method:
docs.dhtmlx.com/doku.php?id=dhtm … ectedrowid