Solved

Dynamically selected and populated combo boxes, MULTIPLE ROWS

Posted on 2003-12-04
14
733 Views
Last Modified: 2012-05-04
I have a pharmacy order entry page, that prepopulates patient data based on id passed to the URL.(IN ASP)
On this page, it has 10 rows for entering items needed.
Each row has a combo box of product codes, a combo box of item desc, a text box of package size, a text box of procedure code and a combo box of quantity.
Upon selection of a product code or item desc in one line, the rest of the values in that row should be populated( they all correspond to one row in table)
I am able to populate the rest based on selection of product code or item desc, but it populates all the rows instead of that particular row.
Also i want to be able to select values from different rows, without affecting previous selected.
Right now i do this using calling the same asp page but passing different parameters to the URL.PLEASE SUGGEST A GOOD SOLUTION TO THIS ONE...I AM STUCK  for DAYS..in this....PLEASE HELP.

Initial URL http://localhost/intakeorder/EnterNewOrder.asp?id=123123123
Upon selection of prodcode or itemdesc
URL: http://localhost/intakeorder/EnterNewOrder.asp?prod=01-AM160&item=A%20and%20D%20Ointment&id=123123123&ct=1
but this populates all rows with same data..
My code is below.

Here is the piece of code that needs to be modfied, and don't know how.OR I CAN USE A NEW SOLUTION THAT EXPERTS CAN GIVE ME
<%for i=1 to 10%>
     <tr>
          <td width="78" class="copy" align="center" bgcolor="#A9B5E5">
               <strong><font size="2" face="Verdana, Arial, Helvetica, sans-serif">
               <select name="ProductCode" style="color: #2B3C86; font-family: Verdana; font-size: 10px; font-weight: bold; border-style: solid; border-width: 0; padding: 0; background-color: #FFFFFF" onchange="doSel(this)">
                    <option>SELECT</option>
                    <%For J = iRecFirst To iRecLast%>
                         <option value="location.href='EnterNewOrder.asp?prod=<%= arrDBData(1, J) %>&item=<%= arrDBData(2,J) %>&id=<%=rs("Patt")%>&ct=<%=i%>'" <%if ProdCode= arrDBData(1,J)  then %>selected <%end if%>><%= arrDBData(1, J) %></option>
                         <%
                         if ProdCode= arrDBData(1,J)  then k=J end if%>
                    <%Next %>
                   
               </select></font></strong>
          </td>
0
Comment
Question by:skandimalla
  • 7
  • 7
14 Comments
 
LVL 12

Expert Comment

by:kingsfan76
Comment Utility
I think i see what you are trying to do.
There are a few problems here.
1st, you are using the same name for all 10 selections.
2nd, you have 10 selections.  if the user uses all 10 selections, the page refresh 10 times.  and each time the user changes a selection the page refreshes.  the code to keep track of the selected info can become unfriendly, and all the page refreshings are very annoying.
To deal with these problems, i suggest using iframe to do the queries in the "background" so the page doesn't need to be refreshed each time a selection is made.

The idea is to have a <iframe style="display:none"> in your page.  setting the display property to none makes it invisible.  Then when user make a selection, call a javascript function to run an ASP page in the iframe to do the query to get the information.  The ASP page in the iframe then writes these info back in the appropriate text field.  All these are done invisible to the user, and the main page does not refresh.

if you are interested in this approach, i can give you some codes on how to do it

kingsfan
0
 
LVL 12

Expert Comment

by:kingsfan76
Comment Utility
well I make up some sample codes while i have time.  It is not the complete code, but hope you get the idea and be able to apply them.  if you have any questions i'll be glad to help

<script>
function soSel(index)
{
   prodCD = MyForm.all["ProductCode"+index].value;
   if (prodCD != "")     //run a ASP page in the iframe
      document.getElementById["iframe1"].src = "getInfo.asp?Index=" + index + "ProdCode=" + prodCD;
}
</script>
<form name="MyForm">
<%for i=1 to 10%>
    <tr>
       <td>
          <select name="ProductCode<%=i%>" onchange="doSel('<%=i%>')">
                   <option>SELECT</option>
                   <%For J = iRecFirst To iRecLast%>
                        <option value="<%= arrDBData(1, J) %>" <%if ProdCode= arrDBData(1,J)  then %>selected <%end if%>><%= arrDBData(1, J) %></option>
                   <%Next %>
           </select>
       
           <input name="PackageSize<%=i%>">
           <input name="ProcedureCode<%=i%>">
<%Next%>

<iframe name="iframe1" id="iframe1" src="EnterNewOrder.asp" style="display:none"></iframe>
</form>

----------------------------

getInfo.asp

<%
i = Request("Index")
productCode = Request("ProdCode")
strSQL = "SELECT * FROM tableName WHERE ProductCode='" & productCOde & "'"
set rst = conn.execute(strSQL)
if not rst.EOF then
  '== write the value back to the main page
%>
<script>
   i = "<%=i%>"
   parent.document.all["PackageSize"+i].value = "<%=rst("PackageSize")%>";
   parent.document.all["ProcedureCode"+i].value = "<%=rst("ProcedureCode")%>";
</script>
<%
end if
%>
--------------------------------
0
 

Author Comment

by:skandimalla
Comment Utility
THANKS FOR REPLYING with a wonderful solution.
I am trying to implement but when u select the item, it is not populating the row.

Either the following in EnterNewOrder.asp
function soSel(index)
{
      
   prodCD = enterbid.all["ProductCode"+index].value;
   if (prodCD != "")     //run a ASP page in the iframe
            document.getElementById["iframe1"].src = "getInfo.asp?Index=" + index + "&ProdCode=" + prodCD;
          
}


or in getInfo.asp
   i = "<%=i%>"
   parent.document.all["PackageSize"+i].value = "<%=rst("PackageSize")%>";
   parent.document.all["HCPCCode"+i].value = "<%=rst("ProcedureCode")%>";
    parent.document.all["Quantity"+i].value = "<%=rst("Quantity")%>";

is not working..

Also if possible could u please provide some code as, how i set my product code and item desc combo boxes are set in getInfo.asp( or in EnterNewOrder.asp page)

REALLY REALLY APPRECIATE YOUR RESPONSE.
0
 
LVL 12

Expert Comment

by:kingsfan76
Comment Utility
hey sorry i got some syntax error in my function.  here's the correct version:

function doSel(index)
{
  prodCD = MyForm.all["ProductCode"+index].value;
  if (prodCD != "")    
     document.getElementById("iframe1").src = "getInfo.asp?Index=" + index + "&ProdCode=" + prodCD;
}

----------------

here's a hard coded page that works.  I don't have a database to query with so I hardcoded some values in there.  paste the code and try it out:

------------------
test1.asp:
------------------
<script>
function doSel(index)
{
  prodCD = MyForm.all["ProductCode"+index].value;
  if (prodCD != "")
     document.getElementById("iframe1").src = "test2.asp?Index=" + index + "&ProdCode=" + prodCD;
}
</script>
<form name="MyForm">
<%for i=1 to 5%>
   <tr>
      <td>
         <select name="ProductCode<%=i%>" onchange="doSel('<%=i%>')">
             <option>SELECT</option>
             <option value="00001">Tylenol</option>
             <option value="00002">Advil</option>
          </select>      
          <input name="PackageSize<%=i%>">
          <input name="ProcedureCode<%=i%>">
<%Next%>
<iframe name="iframe1" id="iframe1" src="test1.asp" style="display:none"></iframe>
</form>

----------------------
test2.asp
----------------------
<%
   i = Request("Index")
   prodCode = Request("ProdCode")
      
   if prodCode = "00001" then
       PackageSize = "60 ml"
       CPTCode = "18400"
   elseif prodCode = "00002" then
       PackageSize = "100 ml"
       CPTCode = "32748"
    end if
%>
<script>
   i = "<%=i%>";
   parent.document.all["PackageSize"+i].value = "<%=PackageSize%>";
   parent.document.all["ProcedureCode"+i].value = "<%=CPTCode%>";
</script>

--------------------------
i'll show you the code to set combobox dynamically in the next step, but i'll need to test it first
0
 
LVL 12

Accepted Solution

by:
kingsfan76 earned 500 total points
Comment Utility
I modified the code in my previous post and come up with some codes that can set combobox value dynamically.  Again everything is hardcoded.  You can copy and past my codes and test them and should work right away.  The codes are quite easy to understand i think.

------------------
test1.asp
------------------

<script>
function doSel(index,selName)
{
  prodCD = MyForm.all[selName+index].value;
  if (prodCD != "")
     document.getElementById("iframe1").src = "test2.asp?Index=" + index + "&ProdCode=" + prodCD + "&SelName=" + selName;
}

function setSelection(selName, selValue)
{
     selSize = MyForm.all[selName].length;   //the size of the combobox
     for (i=0;i<selSize;i++)         //loop through the combobox                
    {
         if (MyForm.all[selName][i].value == selValue)
         {
               MyForm.all[selName].selectedIndex = i;     //set the selected item
               break;        //exit loop
          }
    }
}
</script>
<form name="MyForm">
<table width=640>
<%for i=1 to 5%>
   <tr>
      <td>
         <select name="ProductCode<%=i%>" onchange="doSel('<%=i%>','ProductCode')">
             <option>SELECT</option>
             <option value="00001">00001</option>
             <option value="00002">00002</option>
          </select>
         
          <select name="ProductName<%=i%>" onchange="doSel('<%=i%>','ProductName')">
             <option>SELECT</option>
             <option value="00001">Tylenol</option>
             <option value="00002">Advil</option>
          </select>
       
          <input name="PackageSize<%=i%>">
          <input name="ProcedureCode<%=i%>">
<%Next%>

<iframe name="iframe1" id="iframe1" src="test1.asp" style="display:none"></iframe>
</table>
</form>

----------------
test2.asp
----------------
<%
      i = Request("Index")
      prodCode = Request("ProdCode")
      selName = Request("SelName")
      
      if prodCode = "00001" then
            PackageSize = "60 ml"
            CPTCode = "18400"
      elseif prodCode = "00002" then
            PackageSize = "100 ml"
            CPTCode = "32748"
      end if
      
      if selName = "ProductCode" then      'set the selection for ProductName
             setSelName = "ProductName"
%>
<script>
    i = "<%=i%>";
    parent.window.setSelection("<%=setSelName & i%>","<%=prodCode%>");
</script>
<%
       else
             setSelName = "ProductCode"
%>
<script>
     i = "<%=i%>";
     parent.window.setSelection("<%=setSelName & i%>","<%=prodCode%>");
</script>
<%      
        end if
%>
<script>
   i = "<%=i%>";
   parent.document.all["PackageSize"+i].value = "<%=PackageSize%>";
   parent.document.all["ProcedureCode"+i].value = "<%=CPTCode%>";
</script>

------------------
notes:  when i test these codes, I found out the there is cache problem with the page running in the iframe.  I make changes on test2.asp and then I refresh the page.  When I run it the iframe still runs a cached old version.  I have to close the browser window and open again and run it, then it will load the latest version of test2.asp.  so take note about that when you modify the page running in the iframe.
0
 

Author Comment

by:skandimalla
Comment Utility
Okay....I can now, show all 10 rows, and upon selection of productcode or product name, the other values in that row gets updated.
Now i have another problem, while saving these values...i am unable to access these variables:
Ex:
<% for i = 1 to 10
if Request("HCPCCode")(i) ="SELECT" then
      ProcedureCode=""
else
      ProcedureCode=Request("HCPCCode")(i)
end if

if Request("ProductCode")(i) ="SELECT" then
      ProductCode=""
else
      ProductCode = Request("ProductCode")(i)
end if
next%>

Is this correct syntax? Or am i misssing something. PLEASE ADVISE.
You have been very helpful to me. THANKS.
0
 

Author Comment

by:skandimalla
Comment Utility
I got the answer to the above question...I did the following
 Request("ProductCode"&i)
0
6 Surprising Benefits of Threat Intelligence

All sorts of threat intelligence is available on the web. Intelligence you can learn from, and use to anticipate and prepare for future attacks.

 

Author Comment

by:skandimalla
Comment Utility
I have a another problem now...I will increase the points of the question as it was not in the original question:

Based on ProductCode or Product name selected, right now the package size and quantity are populated as a text box. I want the quantity as a dropdown...
where if the quantity is 3, the dropdown should show 3, 2 and 1
if quantity is 2 then show 2 and 1
if quantity is 1 then show 1
So in:
------------------
test1.asp
------------------
 <input name="PackageSize<%=i%>">
should be made a dropdown list.its value depends on what we get in test2.asp

----------------
test2.asp
----------------
parent.document.all["PackageSize"+i].value = "<%=PackageSize%>";
should be changed

Could u please show me an example. My knowledge of ASP is not so good.
0
 

Author Comment

by:skandimalla
Comment Utility
How can i increase the points? or should i open as a new question?
0
 
LVL 12

Expert Comment

by:kingsfan76
Comment Utility
Yes it can be done with some javascript code as well.  Let me test some codes and i'll post the solution to you.  

meanwhile....  
it seems you cannot increase pts for question with 500+ points.  you can open up a new question, and i'll appreciate the extra points.  but i suggest just leave it right now, and when I post you an accepted solution, you can then open a new question with titile like "points for kingsfan76" and inside just post a message like "points for question <url of this question>".

be back with the solution
0
 
LVL 12

Expert Comment

by:kingsfan76
Comment Utility
Here's one way to generate combo box dynamically.  I only did a sample for Quantity.  if you have problem applying the codes please let me know.

-----------------
test1.asp
------------------
<script>
function doSel(index,selName)
{
 prodCD = MyForm.all[selName+index].value;
 if (prodCD != "")
    document.getElementById("iframe1").src = "test2.asp?Index=" + index + "&ProdCode=" + prodCD + "&SelName=" + selName;
}

function setSelection(selName, selValue)
{
    selSize = MyForm.all[selName].length;   //the size of the combobox
    for (i=0;i<selSize;i++)         //loop through the combobox                
    {
        if (MyForm.all[selName][i].value == selValue)
        {
              MyForm.all[selName].selectedIndex = i;     //set the selected item
              break;        //exit loop
         }
   }
}
</script>
<form name="MyForm">
<table width=640>
<%for i=1 to 5%>
  <tr>
     <td>
        <select name="ProductCode<%=i%>" onchange="doSel('<%=i%>','ProductCode')">
            <option>SELECT</option>
            <option value="00001">00001</option>
            <option value="00002">00002</option>
          </select>
     <td>    
         <select name="ProductName<%=i%>" onchange="doSel('<%=i%>','ProductName')">
            <option>SELECT</option>
            <option value="00001">Tylenol</option>
            <option value="00002">Advil</option>
         </select>
     <td>
         <input name="PackageSize<%=i%>">
     <td>
         <input name="ProcedureCode<%=i%>">
     <td id="Qty<%=i%>">    
         <select name="Quantity<%=i%>" style="width:50">
         </select>
     </td>
<%Next%>

<iframe name="iframe1" id="iframe1" src="test1.asp" style="display:none"></iframe>
</table>
</form>

--------------------
test2.asp
--------------------
<%
     i = Request("Index")
     prodCode = Request("ProdCode")
     selName = Request("SelName")
   
      if prodCode = "00001" then
           PackageSize = "60 ml"
           CPTCode = "18400"
           Quantity = "3"
     elseif prodCode = "00002" then
           PackageSize = "100 ml"
           CPTCode = "32748"
           Quantity = "5"
     end if
   
      if selName = "ProductCode" then      'set the selection for ProductName
            setSelName = "ProductName"
      else
            setSelName = "ProductCode"
      end if
%>
<script>
    i = "<%=i%>";
    parent.window.setSelection("<%=setSelName & i%>","<%=prodCode%>");
</script>

<script>
  i = "<%=i%>";
  parent.document.all["PackageSize"+i].value = "<%=PackageSize%>";
  parent.document.all["ProcedureCode"+i].value = "<%=CPTCode%>";
</script>

<div id="Qty<%=i%>">
<select name="Quantity<%=i%>" style="width:50">
<%
'=== generate the quantity select box
for n = 1 to cint(Quantity)
%>
     <option value=<%=n%>><%=n%></option>
<%
next
%>
</select>
</div>

<script>
    //copy the select box to test1.asp
    i = "<%=i%>"
    parent.document.getElementById("Qty"+i).innerHTML = document.getElementById("Qty"+i).innerHTML;
</script>
0
 

Author Comment

by:skandimalla
Comment Utility
Is this syntax correct?
<script>
    //copy the select box to test1.asp
    i = "<%=i%>"
    parent.document.getElementById("Qty"+i).innerHTML = document.getElementById("Qty"+i).innerHTML;
</script>
0
 

Author Comment

by:skandimalla
Comment Utility
Yes the above syntax seems to alright...becuase, it is setting the quantity corectly as dropdownbox
but it is failing to populate the
parent.document.all["PackageSize"+i].value = "<%=PackageSize%>";
parent.document.all["ProcedureCode"+i].value = "<%=CPTCode%>";

am i missing something...
//copy the select box to test1.asp  what should i copy? i guess i am missing that..
0
 
LVL 12

Expert Comment

by:kingsfan76
Comment Utility
yes.  
>>parent.document.getElementById("Qty"+i)
refers to this object in test1.asp:
>><td id="Qty<%=i%>">

>>document.getElementById("Qty"+i)
refers to this object in test2.asp:
>><div id="Qty<%=i%>">

basically it is assigning the innerHTML codes from one object to anoter
0

Featured Post

How your wiki can always stay up-to-date

Quip doubles as a “living” wiki and a project management tool that evolves with your organization. As you finish projects in Quip, the work remains, easily accessible to all team members, new and old.
- Increase transparency
- Onboard new hires faster
- Access from mobile/offline

Join & Write a Comment

Suggested Solutions

I recently decide that I needed a way to make my pages scream on the net.   While searching around how I can accomplish this I stumbled across a great article that stated "minimize the server requests." I got to thinking, hey, I use more than one…
Hello, all! I just recently started using Microsoft's IIS 7.5 within Windows 7, as I just downloaded and installed the 90 day trial of Windows 7. (Got to love Microsoft for allowing 90 days) The main reason for downloading and testing Windows 7 is t…
In this seventh video of the Xpdf series, we discuss and demonstrate the PDFfonts utility, which lists all the fonts used in a PDF file. It does this via a command line interface, making it suitable for use in programs, scripts, batch files — any pl…
Get a first impression of how PRTG looks and learn how it works.   This video is a short introduction to PRTG, as an initial overview or as a quick start for new PRTG users.

771 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

15 Experts available now in Live!

Get 1:1 Help Now