Window Lookup using a DIV
Description: This example displays a
customer lookup window using a "div" rather than a popup window.
-
Start with a "Simple Page" template.
-
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>
-
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>
-
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>
-
Create three HTML segments which will contain the client names. Name these segments
"lkcomph", "lkcompdet" and "lkcompft".
-
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>
-
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>
-
Add the following HTML to the "lkcompft" segment:
</table>
</center>
</body>
</html>
-
Create a 52 alpha workfield and call it "custnm".
-
In the main function add the following task below the "default" task:
runtask("lookcomp", lookcomp);
-
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);
}
-
Compile and run your program.
|