PDF='MAIN' { ATTRIBUTES='*' { LIBLOBJ='*OBJLIB'; PLATFORM='rpgfree.txt'; USEACTGROUP='1'; ATTACHED='0'; PROJECT='36'; OBJECTNAME='LKUPDIV'; OBJLIBRARY='XL_WEBEXMP'; TITLE='Window Lookup using a DIV'; SOURCEFILE='QRPGLESRC'; SOURCELIBR='XL_WEBEXMP'; ROWCOLOR1='F0F0FF'; ROWCOLOR2='FFFFFF'; WEBPATH='http://esdi.excelsystems.com/wsexmp/'; SET='46'; VERSION='4.00'; CRTBNUM='Revision 1744'; CRTTEMPLT='C:\\Program Files\\ESDI\\WebSmart 6.64\\WebSmart\\Temp\\A Simple Page.tpl'; SAVBNUM='Revision 1744'; LASTLOC='1'; VHTML='N'; LASTSAVE='1/25/2008 12:34:02'; } PANELS='*' { PANEL='MainSeg' { DESC='Main Segment'; DETAILS=' Window Lookup using a DIV

Window Lookup using a DIV

Description:   This example displays a customer lookup window using a "div" rather than a popup window.

You will have to click on "Lookup" and select a company name from the list. This will then automatically populate the fields.


Customer number: Lookup
Customer name:
Address:
City:   State:

  1. Start with a "Simple Page" template.


  2. Add the following JavaScript code between the <head> tags:
    	<script language="Javascript">	
    	// Present a list of companies
    	function lookcust()
    	{
    		
    		// Set the div information
    		xl_GetObj(\'popfrm\').src = "?task=lookcomp";
    		xl_GetObj(\'popdiv\').style.display = \'\';
    		
    		// Set the lookup div location relative to the "lookup" link
    		div = xl_GetObj(\'popdiv\');
    		posX = xl_FindPosX(xl_GetObj(\'lkup\'));    	
    		div.style.left = posX + \'px\';
    		
    		posY = xl_FindPosY(xl_GetObj(\'lkup\')) + 20;
    		div.style.top = posY + \'px\';  
    	}
    	
    	// Populate the form fields with the values from the lookup
    	function populate(custno, cmname, cmaddr, cmcity, cmstate)
    	{
    		xl_GetObj(\'popdiv\').style.display = \'none\';
    		xl_GetObj(\'CMCUST\').value = custno;
    		xl_GetObj(\'CMNAME\').value = cmname;
    		xl_GetObj(\'CMADR1\').value = cmaddr;
    		xl_GetObj(\'CMCITY\').value = cmcity;
    		xl_GetObj(\'CMSTATE\').value = cmstate;
    	}  
    	</script>
    					  
  3. Add the following "div" element, which will contain the look up window:
        <div id="popdiv" style="display: none; position: absolute; border: 1px solid black; 
        	top: 50px; left: 100px; width: 320px; height: 400px; 
        	background-color: white; z-index: 9999; ">
          <iframe id="popfrm" src="" frameborder="0" height="100%" width="100%"></iframe>
        </div>                      
                          
  4. Add the HTML table which will contain the client\'s information:
    	<table id="ordtbl" style="border: thin solid #596975;" cellpadding="5">
    	<tr>
    	  <td>            
    	    Customer number:
    	  </td>
    	  <td>
    	    <input type="text" id="CMCUST" name="CMCUST" size="7" class="box"> <a id="lkup" 
    	    href="Javascript:lookcust();">Lookup</a>
    	  </td>
    	</tr>
    	<tr>
    	  <td>            
    	    Customer name:
    	  </td>
    	  <td>
    	    <input type="text" id="CMNAME" name="CMNAME" size="30" class="box">
    	  </td>
    	</tr>
    	<tr>
    	  <td>
    	    Address:
    	  </td>
    	  <td>
    	    <input type="text" id="CMADR1" name="CMADR1" size="30" class="box">
    	  </td>
    	</tr>
    	<tr>
    	  <td>City:
    	  </td>
    	  <td> <input type="text" id="CMCITY" name="CMCITY" size="15" class="box">   
    	  State: <input type="text" id="CMSTATE" name="CMSTATE" size="2" class="box">
    	  </td>
    	</tr>
    	<tr>
    	  <td colspan="2">
    	    <br>
    	  </td>
    	</tr>
    	</table>
                          


  5. Create three HTML segments which will contain the client names. Name these segments "lkcomph", "lkcompdet" and "lkcompft".

  6. Add the following HTML to the "lkcomph" segment:
      <html>
      <body>
      <p>
        <center>
        <br>    
        <table border="0">
          <tr bgcolor="#69A0D0">
            <th width="300"><font color="#FFFFFF">Company Name</font></th>        
          </tr>
                          
  7. Add the following HTML to the "lkcompdet" segment:
    	<tr bgcolor="<field name=pgmf_altrowclr>">
    	  <td>
    	    <a href="Javascript: parent.populate(\'<field name=CMCUST>\', 
    	    \'<field name=custnm>\', \'<field name=CMADR1>\', 
    	    \'<field name=CMCITY>\', \'<field name=CMSTATE>\')">
    	    <field name=CMNAME>
    	    </a>
    	  </td>  
    	</tr>
                          
  8. Add the following HTML to the "lkcompft" segment:
      </table>
      </center>
      </body>
      </html>
                          
  9. Create a 52 alpha workfield and call it "custnm".


  10. In the main function add the following task below the "default" task:
    runtask("lookcomp", lookcomp);                 
                          
  11. Add the following PML function which will handle the retrieval of the customer names:
    func lookcomp()
    {	
    	CMNAME = getparm("CMNAME");
    	wrthtml(CMNAME);
    	// Output header
    	wrtseg(lkcomph); 
    	
    	rcdcnt=0;
    	
    	// if we have a starting rrn, use that as the
    	// starting point, else use req
    	if(StartRRN > 0)
    	{
    		mu_custl1.rrn = StartRRN;
    		getrcd(MU_CUSTL1, "*RRN", "*NO");
    	}
    	
    	posrcd(MU_CUSTL1, complist); 
    	
    	getnxtrcd(MU_CUSTL1); 
    	
    	// if the key entered is past the end of the file then display 
    	// the last record in the file
    	if (mu_custl1.status <> RecordRetrieved) 
    	{
    		//wrthtml("in if");
    		posrcd(MU_CUSTL1,"*LAST");
    		getprvrcd(MU_CUSTL1);
    	}
    	
    	while (mu_custl1.status == RecordRetrieved)
    	{
    		//wrthtml("in while");
    		if (Firsttime == True) 
    		{
    			Firsttime = False; 
    			
    			// Save key value of last first record in list 
    			StartRRN = mu_custl1.rrn;
    		} 
    		
    		// Replace single quotes to prevent problems in JavaScript call
    		custnm = rplstr(CMNAME, "\'", "!_");
    		
    		wrtseg(lkcompdet); 
    		rcdcnt = rcdcnt + 1;
    		getnxtrcd(MU_CUSTL1);
    	} 
    	
    	// Save rrn value of last record in list 
    	EndRRN = mu_custl1.rrn;
    	
    	wrtseg(lkcompft);	
    }
                          
  12. Compile and run your program.

Program Definition:   lkupdiv.pdw

Rate This Example

Did this knowledge base article help you to achieve your goal?  Yes  No  Don\'t Know

Enter additional comments below.   If you want to hear back from us, include your contact information.

'; } PANEL='lkcomph' { DESC='Lookup Header'; DETAILS='


'; } PANEL='lkcompdet' { DESC='Lookup Detail'; DETAILS=''; } PANEL='lkcompft' { DESC='Lookup Footer'; DETAILS='
Company Name
'; } } PREVIEWS='*' { DEFAULT='MainSeg'; PREVIEW='MainSeg' { SEG='MainSeg'; } } ACTIONS='func Main() { // Program Name: LKUPDIV // Program Title: Window Lookup using a DIV // Created by: Oscar Gomez // Template family: Idaho // Template name: Simple Page // Purpose: // Program Modifications: // Determine which library list will be used setlibl("*OBJLIB"); // Open all files openfile("*ALL"); //declare fields for rating the page crtfld(RPNUM, 5, "N", 0, "Number"); crtfld(RPTYPE, 1, "A", 0, "Page Type"); crtfld(RPSOPR, 1, "A", 0, "Solve Problem?"); crtfld(RPCOMM, 4000, "A", 0, "Comment"); //This workfield is needed to return to examples list crtfld(wsnum, 5, "N", 0, "Example number from exlist app"); crtfld(rtncod, 1, "A", 0, "valid smurf return code"); // Starting and ending relative record numbers are used to control Next/Previous page of records crtfld(StartRRN, 9,"N",0,"Starting RRN"); crtfld(EndRRN, 9,"N",0,"Ending RRN"); // Record counter to determine how many records have been output to the list crtfld(rcdcnt, 5,"N",0,"Number of records written to list "); // Page size determines the maximum number of records (rows) contained in the list crtfld(listsize, 5,"N",0,"Page size of list-max records"); crtfld(custnm, 52, "A", 0, "Customer Name workfield"); // Get rrn from URL to determine if a starting value was specified StartRRN = getparm("rrn"); crtklist(complist, CMNAME); wsnum = getparm("wsnum"); skipsmurfchk(); // Instead do our own check rtncod = isvalidsmurf(); if(rtncod == "1") { gensmurfid("*IFNONE", "*DAY",1, "*YES", "*YES", "*YES"); //set cookie params for use in ws example rate this page feature setsmurf("wsnumb", wsnum); } else { wsnum = getsmurf("wsnumb"); } // As a default task for this program, execute the generic function runtask("DEFAULT", generic); runtask("lookcomp", lookcomp); } func generic() { wrtseg(MainSeg); } func lookcomp() { CMNAME = getparm("CMNAME"); wrthtml(CMNAME); // Output header wrtseg(lkcomph); rcdcnt=0; // if we have a starting rrn, use that as the // starting point, else use req if(StartRRN > 0) { mu_custl1.rrn = StartRRN; getrcd(MU_CUSTL1, "*RRN", "*NO"); } posrcd(MU_CUSTL1, complist); getnxtrcd(MU_CUSTL1); // if the key entered is past the end of the file then display the last record in the file if (mu_custl1.status <> RecordRetrieved) { //wrthtml("in if"); posrcd(MU_CUSTL1,"*LAST"); getprvrcd(MU_CUSTL1); } while (mu_custl1.status == RecordRetrieved) { //wrthtml("in while"); if (Firsttime == True) { Firsttime = False; // Save key value of last first record in list StartRRN = mu_custl1.rrn; } // Prevent problem with single quotes in JavaScript call custnm = rplstr(CMNAME, "\'", "!_"); wrtseg(lkcompdet); rcdcnt = rcdcnt + 1; getnxtrcd(MU_CUSTL1); } // Save rrn value of last record in list EndRRN = mu_custl1.rrn; wrtseg(lkcompft); }'; FILES='*' { FILE='MU_CUSTL1' { LIBRARY='XL_WEBDEMO'; RCDFORMAT='R_CUSTF '; LEVELID='1070921111629'; RFLEVELID='403ABD661EC5A'; EXTDS='0'; } } }