Dynamically populating a drop down list.

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • chandhseke
    New Member
    • Jun 2009
    • 92

    Dynamically populating a drop down list.

    Hi Folks,

    I have a question regarding binding dropdown list values. I have a set of names which i will be adding to a drop down list box. While the user selects an item from dropdown list, the person's email address should automatically come up in the text box next to it.

    Name(Dropdown items) Email
    1. John John.xxx@exampl e.com
    2. Adam Adam.yyy@exampl e.com
    3. Ramesh Ramesh@example. com

    Please help/guide me so as how to achieve this requirement. Thanks in advance!!

    Regards,
    Chandhseke
    Last edited by Dormilich; May 10 '10, 12:18 PM. Reason: please use generic domains in examples
  • Dormilich
    Recognized Expert Expert
    • Aug 2008
    • 8694

    #2
    If you have something like
    Code:
    <select id="email">
        <option value="John.xxx@example.com">John</option>
    // …
    </select>
    you can simply use a function to write the values to the text box.
    Code:
    function passAddress()
    {
        document.getElementById("textboxid").value = this.value;
    }
    document.getElementById("email").addEventListener("change", passAddress, false);
    // use cross-browser event handling for IE …

    Comment

    • chandhseke
      New Member
      • Jun 2009
      • 92

      #3
      Thank you!!. Since we are using javascript function to populate the Email address to text box, is there any drawbacks like buffering issue. Since sometimes in my code all the drop down values will get vanished off during approval process(Same page will be sent to different people based on number of levels).

      Please comment on this?

      Regards,
      Chandhseke

      Comment

      • chandhseke
        New Member
        • Jun 2009
        • 92

        #4
        Any update on my above thread? Please advise.

        Regards,
        Chandhseke

        Comment

        • Dormilich
          Recognized Expert Expert
          • Aug 2008
          • 8694

          #5
          I do not understand the problem …

          Comment

          • chandhseke
            New Member
            • Jun 2009
            • 92

            #6
            Hi,

            As per the above conversation we had couple of months before, i used the same techinique in order to develop a dynamic drop down list by binding the dropdown values. The initial requirement was if an end user selects an item from dropdown then its his/her email address should automatically pop-up in the text box. Please find the below code.

            //JavaScript to popup email address in a text box based on item selected from a drop down list.
            Code:
            function addit()
                { 
                    document.getElementById("Category_Email").value = document.getElementById("CatProcDir").value;
                    document.getElementById("HidCatProcDir").value = document.getElementById("CatProcDir").options[document.getElementById("CatProcDir").selectedIndex].text;
                }
                
            function addEmail()
            {
                document.getElementById("OG_Email").value = document.getElementById("OGC_Name").value; 
                document.getElementById("HidOG_Email").value = document.getElementById("OGC_Name").options[document.getElementById("OGC_Name").selectedIndex].text;
            }
            //Actual ASP/HTML code

            Code:
            <%@ Language = VBScript %>
            <% Response.Buffer = true %>
            <html>
            <head>
            <title>Supplier Decision Summary</title>
            </head>
            <body bgcolor="#666666">
            <form action="SQLInsert.asp" method="post"  name="SDS_step_one" onsubmit="return validate()">
            <tr>
                   <td colspan="2" style="height: 32px">Regional/Category Procurement Director </td>
                   <td colspan="3" style="width: 999px; height: 32px;">
                  <select name="CatProcDir" id="CatProcDir" style="width: 242px" onchange="addit()">
                   <option value="">Select</option>
                   <option value="Chris.Jacob@au.unisys.com">(APAC)Jacob, Chris </option>
                   <option value="Dave.McAdam@au.unisys.com">(APAC)McAdam, Dave</option>
                   <option value="tony.o'connor@gb.unisys.com">(EMEA)O’Connor, Tony </option>
                   <option value="Graham.Chalmers@gb.unisys.com">(Global)Chalmers, Graham</option>
                   <option value="Martin.Sturla@unisys.com">(LACR)Sturla, Martin</option>
                   <option value="Christopher.Bowe@unisys.com">(NA)Bowe, Chris</option>
                   <option value="Jay.McKeever@unisys.com">(NA)McKeever, Jay</option>
                   <option value="mark.pagliaro@unisys.com">(NA)Pagliaro, Mark</option>
                </select>-->
                   <select name="CatProcDir" id="CatProcDir" style="width: 242px" onchange="addit()">
                   <option value="">Select</option>
                    <%
                    SQLCatProc = "Select * from SDS_ProcApprovers where Deleted = 'No' Order By Cat_Proc_Name ASC" 
                    Set Rs1 = oConn.Execute(SQLCatProc)
                    Do Until Rs1.EOF
                    %>
                    <option value="<%=Rs1("Cat_Proc_Email")%>"><%=Rs1("Cat_Proc_Name")%></option>
                    <%
                    Rs1.MoveNext
                    loop
                    Rs1.close
                    %>
                   </select>
                   </td>
            
            </td>
                   <td colspan style="height: 32px"><input type="text" name="Category_Email" style="width: 250px" />
                   <input type="hidden" name="HidCatProcDir" value="" />
                   </td>
                   </tr>
            <tr>
                   <td colspan="2">OGC Contact</td>
                   <td colspan="3" style="width: 999px">
                   <select name="OGC_Name" onchange="return addEmail()" style="width: 240px">
                   <option value="">Select</option>
                   <%
                    SQLOGC = "select * from OGC_Contact Where Deleted = 'No' order by OGC_Contact ASC" 
                    Set Rs1 = oConn.Execute(SQLOGC)
                    Do Until Rs1.EOF
                    %>
                    <option value="<%=Rs1("OGC_Email")%>"><%=Rs1("OGC_Contact")%></option>
                    <%
                    Rs1.MoveNext
                    loop
                    Rs1.close
                    %>
                   </select>
                   </td>
                   <td colspan="3" style="width: 1259px"><input type="text" name="OG_Email" id="OG_Email" style="width: 250px" maxlength="100"/>
                   <input type="hidden" name="HidOG_Email" value="" />
                   </td>
                   </tr>
             <input id="Submit" style="width: 180px" type="submit" value="Submit" onclick="document.SDS_step_one.Submitform.value = 'Submitted'"/>
             <input type="Submit" value="Save and Submit Later" name="Save" onclick="document.SDS_step_one.Submitform.value = 'Saved'"/>
            </table>  
            </form>
            </body>
            </html>

            //SQLnew.asp in formaction will insert the form values to DB table.

            Code:
            <%@LANGUAGE="VBSCRIPT" CODEPAGE="1252"%>
            <!--#include file="Connection.asp" -->
            
            <%
            Select Case Trim(Request.Form("Submitform"))
            	Case "Submitted"
            SQLAdd = "Insert into SDS (Last_Update, Scope, Category, Sourcing_Methodology, OGC_name, Approval2alt, Category_MGR, Approval3alt, Proc_Director, Approval6alt )" & _
                     "Values ('" & Today & "','" & Scope & "','" & Category & "','" & Source_method & "','" & HidOG_Email & "','" & Com_Email & "','" & HidCom_Email & "','" & OG_Email & "','" & HidCatProcDir & "','" & Category_Email & "')"
            
            oConn.Execute SQLAdd
            This form carries these data to 9 approvers for approval, but sometimes data in the drop down list will get disappeared automatically(b oth in form/DB).

            Please help if there is anything that needs to be corrected in my code. THis is a old application therefore old technology being used.

            Regards,
            Chandhseke

            Comment

            Working...