Searchable popup list to fill parent window

  • 73blazer
  • Born
  • Born
  • 73blazer
  • Posts: 1

Post 3+ Months Ago

Hello,
I've written some javascript/php to popup a list of names from a database and when the user picks a name in the list it fills out the parent form box with that name. However, there are many many names in the list now and I need a way to make the list searchable. Just a simple search box at the top that when a name or part of a name is typed it takes you to that area of the list. I just can't seem to think of a way. Is there a way, I'm pretty new to javascript. Any help is most appreciated. Thanks.

Here's my page:
Code: [ Select ]
 <html>
 <?
  /* Find the user and convert to upper case for selection from the DB */
  /* ------------------------------------------------------------------- */
  $ENOVIAUSER=strtoupper($HTTP_ENOVUSER);

  /* PHP to select number of entries for email address from VPM database */
  /* ------------------------------------------------------------------- */
  $db2id=`db2user`;
  $db2passwd=`db2user`;
  $dbconn = odbc_connect("VPMDB",$db2id,$db2passwd);
  if($dbconn==0)
  {
   $a = odbc_errormsg();
   echo($a);
  }
  else
  {
   $dbselect='select count("email") from vpmadm."person" where "email" is not null';
   $dbselect2="select \"email\" from vpmadm.\"person\" where \"id\"='$ENOVIAUSER'";
   $result = odbc_exec($dbconn, $dbselect);
   $result2 = odbc_exec($dbconn, $dbselect2);
   while(odbc_fetch_row($result))
   {
    $NUMEMAIL=odbc_result($result,1);
   }
   while(odbc_fetch_row($result2))
   {
    $USEREMAIL=odbc_result($result2,1);
   }
   odbc_commit($dbconn);
   odbc_close_all();
  }
  /* ------------------------------------------------------------------- */
 ?>
<head>
  <SCRIPT TYPE="text/javascript">
  <!--
  function popup(mylink, windowname)
  {
  if (! window.focus)return true;
  var href;
  if (typeof(mylink) == 'string')
    href=mylink;
  else
    href=mylink.href;
  window.open(href, windowname, 'width=450,height=450,scrollbars=yes');
  return false;
  }
  //-->
  </SCRIPT>

 <title>Any title</title>
  <SCRIPT LANGUAGE='Javascript'>
  function MakeArray(n){
   this.length=n
   return this
  }
  function getHelpValues(numText){
   var helpOwnValues
  if(numText == 0){
  helpOwnValues = new MakeArray(<?PRINT $NUMEMAIL?>)
   <?
   /* PHP to select email address from VPM database */
   /* --------------------------------------------- */
    $dbconn = odbc_connect("VPMDB",$db2id,$db2passwd);
    if($dbconn==0)
    {
     $a = odbc_errormsg();
     echo($a);
    }
    else
    {
     $dbselect='select "email" from vpmadm."person" where "email" is not null order by "last_name"';
     $result = odbc_exec($dbconn, $dbselect);
     $x=1;
     while(odbc_fetch_row($result))
     {
      $outval="helpOwnValues[$x] = '";
      $outval.=odbc_result($result,1);
      $outval.="';";
      $x=$x+1;
      PRINT $outval;
     }
     odbc_commit($dbconn);
     odbc_close_all();
    }
   /* --------------------------------------------- */
   ?>
  }
  return helpOwnValues
  }
  function popupHelpValues(numText)
  {
  var fieldtoUpdate = event.srcElement.sourceIndex-1
  var newWindow = window.open("","fenetre","resizable=no,scrollbars=yes,location=no,top=100,left=100,width=255,height=900")
  var content = "<HTML><head><title>Help values choice</title>\n"
  content +="<link rel='stylesheet' type='text/css' href='http://<? print $SERVER_NAME?>/enovia_portal/styles/portal.css'>\n"
  content +="<"+"S"+"CR"+"IPT language='javascript'>\n"
  content +="function sendSelect(strValue){  \n"
  content +=" self.creator.document.all["+fieldtoUpdate+"].value=strValue;\n"
  content +=" closeMyWindow();\n"
  content +="}\n"
  content +="function closeMyWindow(){    \n"
  content +=" self.creator.document.all["+fieldtoUpdate+"].blur();\n"
  content +=" window.close();\n"
  content +="}\n"
  content +="<"+"/"+"SCR"+"IPT></head><BODY><center><FORM NAME='helpValuesForm'>\n"
  content +="<TABLE WIDTH='100%' CELLPADDING=2 CELLSPACING=1 BORDER=0><TR class='header3'>\n"
  content +="<TD>Help values</TD>\n "
  var helpNumValues = getHelpValues(numText)
  for(var i=1; i<= helpNumValues.length; i++){
    if(i%2 == 0)
        content +="       <TR CLASS='band'>\n"
    else
        content +="       <TR>\n"
    content +="   <TD NOWRAP>\n"
    content +="   <A HREF='script:' onclick='sendSelect(\""+helpNumValues[i]+"\")'>"+helpNumValues[i]+"</A>\n"
    content +="   </TD></TR>\n"
  }
  content +="</TABLE>\n"
  content +="<P><A HREF='script:' onclick='closeMyWindow()'>close</A></P>\n"
  content +="</FORM></center></body></html>"
  newWindow.document.open('text/html', 'replace');
  newWindow.document.write(content);
  newWindow.document.close();
  newWindow.creator = window
  }

  function NpopUp(loc,eyeD,X,Y){
   window.open(loc,eyeD,"toolbar=no,location=0,directories=no,status=no,menubar=0,scrollbars=yes,resizable=0,width=" + X + ",height=" + Y + "'");
  }

</SCRIPT>

</head>
<body bgcolor=#ffffff text=#000000>
 <H1>
 <CENTER>
  Any Title for page
 </CENTER>
 </H1>
 <P>
 <hr noshade size=5 width=100% >
 <br>

 <form name=namesForm method=post action=post.php>

    <?

     /* PHP to Correct HYPO in case the customize menu did not encode spaces     */
     /*  (This is to correct a bug in v5r12sp5 if the S_HYPERLO_NAME is blank   */
     /*   sometimes it sends HYPO=nothing, which is bad and sometimes it sends   */
     /*   HYPO=%20 which is right (a Space). It is unpredictable, so code is    */
     /*   needed to correct the situation.                     */
     /* ---------------------------------------------------------------------------- */
      if ($HYPO=="") {
       $HYPO=" ";
      }
     /* PHP to Print out Form Variables passed from 3dcom SendBookmark Menu Function */
     /* ---------------------------------------------------------------------------- */
      $PARTNUMBER=stripslashes($PARTNUMBER);
      $HYPO=stripslashes($HYPO);
      $PARTNUMBER=htmlspecialchars($PARTNUMBER);
      $HYPO=htmlspecialchars($HYPO);
      PRINT "<input name=UUID type=hidden value=\"$UUID\">";
      PRINT "<input name=PARTNUMBER type=hidden value=\"$PARTNUMBER\">";
      PRINT "<input name=VERSION type=hidden value=\"$VERSION\">";
      PRINT "<input name=HYPO type=hidden value=\"$HYPO\">";
      PRINT "<input name=TYPE type=hidden value=\"$TYPE\">";
      PRINT "<input name=CMS_TYPE_REP type=hidden value=\"$CMS_TYPE_REP\">";
      PRINT "<input name=CMS_NEXT type=hidden value=\"$CMS_NEXT\">";
      PRINT "<input name=CMC_REVISION type=hidden value=\"$CMC_REVISION\">";
      PRINT "<input name=DCS_TYPE_REP type=hidden value=\"$DCS_TYPE_REP\">";
      PRINT "<input name=DCS_NAME type=hidden value=\"$DCS_NAME\">";
     /* ---------------------------------------------------------------------------- */
    ?>

  <CENTER><B>Please Enter the Desired Recipients full email address<br></b>
  <CENTER>
  <BR>
  <P>
  <INPUT CLASS='mandatory' id=namesList NAME='EMAIL' TYPE='TEXT' SIZE='40'>
  <a href="javascript:NpopUp('names.php','names','300','300')"><IMG ALT='Help Values' BORDER='0' SRC='http://<? print $SERVER_NAME ?>/enovia_portal/java/./Resources/butsearch.gif'></a>

  <IMG ALT='' BORDER='0' SRC='http://<? print $SERVER_NAME ?>/enovia_portal/java/./Resources/mandatory.gif'>
  </P>
  </CENTER>
  <B><CENTER>Please Enter Your full email address</B>
  <font size =1><A HREF="why.html" onClick="return popup(this, 'notes')">Why do I need to enter my Email address? </A></font>
  <CENTER>
  <P>
  <INPUT CLASS='mandatory' NAME='SENDER' TYPE='TEXT' SIZE='40' VALUE='<?echo $USEREMAIL;?>'>
  <IMG ALT='Help Values' onClick='popupHelpValues(0)' BORDER='0' SRC='http://<? print $SERVER_NAME ?>/enovia_portal/java/./Resources/butsearch.gif'>

  <IMG ALT='' BORDER='0' SRC='http://<? print $SERVER_NAME ?>/enovia_portal/java/./Resources/mandatory.gif'>
  </P>
  <B>Enter an optional message to recipient:</B>
  <br>
<p><textarea rows="5" name="MFU" cols="50">
   </textarea> &nbsp;&nbsp;&nbsp;<br><input TYPE="RESET" VALUE="Reset" ALIGN="texttop"> </p>
  <br>
  <p>
  <B><input type=submit value="Send Bookmark"></B></CENTER>
 </form>
  <hr noshade size=5 width=90% >
  <b>
  <A HREF="what.html" onClick="return popup(this, 'notes')">What is this "SendBookmark" function?</A> |
  <A HREF="problems.html" onClick="return popup(this, 'notes')"> Known Problems</A> |
  <A HREF=mailto:bpaliga@oh.hra.com> Questions/Comments</A>
  </b>
  <hr noshade size=5 width=90% >

</body>
</html>
  1.  <html>
  2.  <?
  3.   /* Find the user and convert to upper case for selection from the DB */
  4.   /* ------------------------------------------------------------------- */
  5.   $ENOVIAUSER=strtoupper($HTTP_ENOVUSER);
  6.   /* PHP to select number of entries for email address from VPM database */
  7.   /* ------------------------------------------------------------------- */
  8.   $db2id=`db2user`;
  9.   $db2passwd=`db2user`;
  10.   $dbconn = odbc_connect("VPMDB",$db2id,$db2passwd);
  11.   if($dbconn==0)
  12.   {
  13.    $a = odbc_errormsg();
  14.    echo($a);
  15.   }
  16.   else
  17.   {
  18.    $dbselect='select count("email") from vpmadm."person" where "email" is not null';
  19.    $dbselect2="select \"email\" from vpmadm.\"person\" where \"id\"='$ENOVIAUSER'";
  20.    $result = odbc_exec($dbconn, $dbselect);
  21.    $result2 = odbc_exec($dbconn, $dbselect2);
  22.    while(odbc_fetch_row($result))
  23.    {
  24.     $NUMEMAIL=odbc_result($result,1);
  25.    }
  26.    while(odbc_fetch_row($result2))
  27.    {
  28.     $USEREMAIL=odbc_result($result2,1);
  29.    }
  30.    odbc_commit($dbconn);
  31.    odbc_close_all();
  32.   }
  33.   /* ------------------------------------------------------------------- */
  34.  ?>
  35. <head>
  36.   <SCRIPT TYPE="text/javascript">
  37.   <!--
  38.   function popup(mylink, windowname)
  39.   {
  40.   if (! window.focus)return true;
  41.   var href;
  42.   if (typeof(mylink) == 'string')
  43.     href=mylink;
  44.   else
  45.     href=mylink.href;
  46.   window.open(href, windowname, 'width=450,height=450,scrollbars=yes');
  47.   return false;
  48.   }
  49.   //-->
  50.   </SCRIPT>
  51.  <title>Any title</title>
  52.   <SCRIPT LANGUAGE='Javascript'>
  53.   function MakeArray(n){
  54.    this.length=n
  55.    return this
  56.   }
  57.   function getHelpValues(numText){
  58.    var helpOwnValues
  59.   if(numText == 0){
  60.   helpOwnValues = new MakeArray(<?PRINT $NUMEMAIL?>)
  61.    <?
  62.    /* PHP to select email address from VPM database */
  63.    /* --------------------------------------------- */
  64.     $dbconn = odbc_connect("VPMDB",$db2id,$db2passwd);
  65.     if($dbconn==0)
  66.     {
  67.      $a = odbc_errormsg();
  68.      echo($a);
  69.     }
  70.     else
  71.     {
  72.      $dbselect='select "email" from vpmadm."person" where "email" is not null order by "last_name"';
  73.      $result = odbc_exec($dbconn, $dbselect);
  74.      $x=1;
  75.      while(odbc_fetch_row($result))
  76.      {
  77.       $outval="helpOwnValues[$x] = '";
  78.       $outval.=odbc_result($result,1);
  79.       $outval.="';";
  80.       $x=$x+1;
  81.       PRINT $outval;
  82.      }
  83.      odbc_commit($dbconn);
  84.      odbc_close_all();
  85.     }
  86.    /* --------------------------------------------- */
  87.    ?>
  88.   }
  89.   return helpOwnValues
  90.   }
  91.   function popupHelpValues(numText)
  92.   {
  93.   var fieldtoUpdate = event.srcElement.sourceIndex-1
  94.   var newWindow = window.open("","fenetre","resizable=no,scrollbars=yes,location=no,top=100,left=100,width=255,height=900")
  95.   var content = "<HTML><head><title>Help values choice</title>\n"
  96.   content +="<link rel='stylesheet' type='text/css' href='http://<? print $SERVER_NAME?>/enovia_portal/styles/portal.css'>\n"
  97.   content +="<"+"S"+"CR"+"IPT language='javascript'>\n"
  98.   content +="function sendSelect(strValue){  \n"
  99.   content +=" self.creator.document.all["+fieldtoUpdate+"].value=strValue;\n"
  100.   content +=" closeMyWindow();\n"
  101.   content +="}\n"
  102.   content +="function closeMyWindow(){    \n"
  103.   content +=" self.creator.document.all["+fieldtoUpdate+"].blur();\n"
  104.   content +=" window.close();\n"
  105.   content +="}\n"
  106.   content +="<"+"/"+"SCR"+"IPT></head><BODY><center><FORM NAME='helpValuesForm'>\n"
  107.   content +="<TABLE WIDTH='100%' CELLPADDING=2 CELLSPACING=1 BORDER=0><TR class='header3'>\n"
  108.   content +="<TD>Help values</TD>\n "
  109.   var helpNumValues = getHelpValues(numText)
  110.   for(var i=1; i<= helpNumValues.length; i++){
  111.     if(i%2 == 0)
  112.         content +="       <TR CLASS='band'>\n"
  113.     else
  114.         content +="       <TR>\n"
  115.     content +="   <TD NOWRAP>\n"
  116.     content +="   <A HREF='script:' onclick='sendSelect(\""+helpNumValues[i]+"\")'>"+helpNumValues[i]+"</A>\n"
  117.     content +="   </TD></TR>\n"
  118.   }
  119.   content +="</TABLE>\n"
  120.   content +="<P><A HREF='script:' onclick='closeMyWindow()'>close</A></P>\n"
  121.   content +="</FORM></center></body></html>"
  122.   newWindow.document.open('text/html', 'replace');
  123.   newWindow.document.write(content);
  124.   newWindow.document.close();
  125.   newWindow.creator = window
  126.   }
  127.   function NpopUp(loc,eyeD,X,Y){
  128.    window.open(loc,eyeD,"toolbar=no,location=0,directories=no,status=no,menubar=0,scrollbars=yes,resizable=0,width=" + X + ",height=" + Y + "'");
  129.   }
  130. </SCRIPT>
  131. </head>
  132. <body bgcolor=#ffffff text=#000000>
  133.  <H1>
  134.  <CENTER>
  135.   Any Title for page
  136.  </CENTER>
  137.  </H1>
  138.  <P>
  139.  <hr noshade size=5 width=100% >
  140.  <br>
  141.  <form name=namesForm method=post action=post.php>
  142.     <?
  143.      /* PHP to Correct HYPO in case the customize menu did not encode spaces     */
  144.      /*  (This is to correct a bug in v5r12sp5 if the S_HYPERLO_NAME is blank   */
  145.      /*   sometimes it sends HYPO=nothing, which is bad and sometimes it sends   */
  146.      /*   HYPO=%20 which is right (a Space). It is unpredictable, so code is    */
  147.      /*   needed to correct the situation.                     */
  148.      /* ---------------------------------------------------------------------------- */
  149.       if ($HYPO=="") {
  150.        $HYPO=" ";
  151.       }
  152.      /* PHP to Print out Form Variables passed from 3dcom SendBookmark Menu Function */
  153.      /* ---------------------------------------------------------------------------- */
  154.       $PARTNUMBER=stripslashes($PARTNUMBER);
  155.       $HYPO=stripslashes($HYPO);
  156.       $PARTNUMBER=htmlspecialchars($PARTNUMBER);
  157.       $HYPO=htmlspecialchars($HYPO);
  158.       PRINT "<input name=UUID type=hidden value=\"$UUID\">";
  159.       PRINT "<input name=PARTNUMBER type=hidden value=\"$PARTNUMBER\">";
  160.       PRINT "<input name=VERSION type=hidden value=\"$VERSION\">";
  161.       PRINT "<input name=HYPO type=hidden value=\"$HYPO\">";
  162.       PRINT "<input name=TYPE type=hidden value=\"$TYPE\">";
  163.       PRINT "<input name=CMS_TYPE_REP type=hidden value=\"$CMS_TYPE_REP\">";
  164.       PRINT "<input name=CMS_NEXT type=hidden value=\"$CMS_NEXT\">";
  165.       PRINT "<input name=CMC_REVISION type=hidden value=\"$CMC_REVISION\">";
  166.       PRINT "<input name=DCS_TYPE_REP type=hidden value=\"$DCS_TYPE_REP\">";
  167.       PRINT "<input name=DCS_NAME type=hidden value=\"$DCS_NAME\">";
  168.      /* ---------------------------------------------------------------------------- */
  169.     ?>
  170.   <CENTER><B>Please Enter the Desired Recipients full email address<br></b>
  171.   <CENTER>
  172.   <BR>
  173.   <P>
  174.   <INPUT CLASS='mandatory' id=namesList NAME='EMAIL' TYPE='TEXT' SIZE='40'>
  175.   <a href="javascript:NpopUp('names.php','names','300','300')"><IMG ALT='Help Values' BORDER='0' SRC='http://<? print $SERVER_NAME ?>/enovia_portal/java/./Resources/butsearch.gif'></a>
  176.   <IMG ALT='' BORDER='0' SRC='http://<? print $SERVER_NAME ?>/enovia_portal/java/./Resources/mandatory.gif'>
  177.   </P>
  178.   </CENTER>
  179.   <B><CENTER>Please Enter Your full email address</B>
  180.   <font size =1><A HREF="why.html" onClick="return popup(this, 'notes')">Why do I need to enter my Email address? </A></font>
  181.   <CENTER>
  182.   <P>
  183.   <INPUT CLASS='mandatory' NAME='SENDER' TYPE='TEXT' SIZE='40' VALUE='<?echo $USEREMAIL;?>'>
  184.   <IMG ALT='Help Values' onClick='popupHelpValues(0)' BORDER='0' SRC='http://<? print $SERVER_NAME ?>/enovia_portal/java/./Resources/butsearch.gif'>
  185.   <IMG ALT='' BORDER='0' SRC='http://<? print $SERVER_NAME ?>/enovia_portal/java/./Resources/mandatory.gif'>
  186.   </P>
  187.   <B>Enter an optional message to recipient:</B>
  188.   <br>
  189. <p><textarea rows="5" name="MFU" cols="50">
  190.    </textarea> &nbsp;&nbsp;&nbsp;<br><input TYPE="RESET" VALUE="Reset" ALIGN="texttop"> </p>
  191.   <br>
  192.   <p>
  193.   <B><input type=submit value="Send Bookmark"></B></CENTER>
  194.  </form>
  195.   <hr noshade size=5 width=90% >
  196.   <b>
  197.   <A HREF="what.html" onClick="return popup(this, 'notes')">What is this "SendBookmark" function?</A> |
  198.   <A HREF="problems.html" onClick="return popup(this, 'notes')"> Known Problems</A> |
  199.   <A HREF=mailto:bpaliga@oh.hra.com> Questions/Comments</A>
  200.   </b>
  201.   <hr noshade size=5 width=90% >
  202. </body>
  203. </html>


Again, any ideas are most appreciated. Thanks

73blazer
  • Anonymous
  • Bot
  • No Avatar
  • Posts: ?
  • Loc: Ozzuland
  • Status: Online

Post 3+ Months Ago

  • Rabid Dog
  • Web Master
  • Web Master
  • User avatar
  • Posts: 3245
  • Loc: South Africa

Post 3+ Months Ago

I wrote an invoicing and stock management system in php that did exactly what you are looking for.

The user would type in the stock item and the more they type the shorter the list got ( obviously matching the name of the stock item)
If they selected the item from the list it would then populate the invoice form with the item description, price etc.

Don't have it here though - will bring some sample code on monday.

Post Information

  • Total Posts in this topic: 2 posts
  • Users browsing this forum: No registered users and 70 guests
  • You cannot post new topics in this forum
  • You cannot reply to topics in this forum
  • You cannot edit your posts in this forum
  • You cannot delete your posts in this forum
  • You cannot post attachments in this forum
 
 

© 1998-2014. Ozzu® is a registered trademark of Unmelted, LLC.