Hello and welcome to our community! Is this your first visit?
Register
Enjoy an ad free experience by logging in. Not a member yet? Register.
Page 1 of 2 12 LastLast
Results 1 to 15 of 19
  1. #1
    Abd
    Abd is offline
    New Coder
    Join Date
    Aug 2002
    Location
    Lagos, Nigeria
    Posts
    99
    Thanks
    0
    Thanked 0 Times in 0 Posts

    ComboBox Item Populating a Form

    Hi All,

    I pls need a help, may be a sample code or something on, I want to be able to search a user with a user code, get a form populate if the user exist in the Database, but at the same time in one corner of the form I want to be able to see the list of other user's code in a ComboBox from the Database, and onclicking on any user code in the ComboBox the same form should be populated with the user' information.

    Right now I have a functional Application but without the ComboBox functionality.

    Thanks

    Abdul
    Abdul

  • #2
    raf
    raf is offline
    Master Coder
    Join Date
    Jul 2002
    Posts
    6,589
    Thanks
    0
    Thanked 0 Times in 0 Posts
    Whats the problem? Building the combobox or the onclick submit or ???

  • #3
    Abd
    Abd is offline
    New Coder
    Join Date
    Aug 2002
    Location
    Lagos, Nigeria
    Posts
    99
    Thanks
    0
    Thanked 0 Times in 0 Posts
    raf,

    not Building the ComboBox, I can build a ComboBox that will get populated with a database data, BUT the problem is I want onclicking any usercode or item in the ComboBox it should populate the same Form where the ComboBox appear, do you get my point?

    Abdul
    Abdul

  • #4
    raf
    raf is offline
    Master Coder
    Join Date
    Jul 2002
    Posts
    6,589
    Thanks
    0
    Thanked 0 Times in 0 Posts
    I see. I posted some code for a similar problem here
    populating drop down menu from the database
    look for the post of me on 03-03-2003 (9.20 h)

    The code build a dropdown, and on submit, posts to itself and loads the same page with an additional dropdown. It's basically the same mechanisme then for your problem. You need to build a mutipurpose page. The first time the page is loaded, the dropdown is created and shown. If you submit the form (after choosing an option from the dropdown) the script checks if there is a value for the dropdown in the form-colection. If there is one, the sql statement to select the info is ran and is shown. (just as the dropdown) If you pick another option from the dropdown, a new select will be made etc etc.

    So it's basically just adding a condition on top of the page and put the code to generate the dropdown and to pupulate the form together. Like:

    if Len(request.form("dropdownname")) = 0 then
    your code to build and display dropdown
    (in the select tag, you need an onclick="submit();", and the method="post" and name="pagename"
    else
    your code to build and display the dropdown + perhaps set the picked value as selected
    your code to select the info and display it
    end if

    But i wouldn't do that. For starters, if you want the dropdown in the same form, you need to recreate it each time they pick another option! So this means a call to the webserver, a call to the db, looping through the recordset, building the dropdown. So this means a lott of overhead and tranfic.
    If you have an onclick, you'll also have some 'false-hits' which means useless trafic.

    So, i'd suggest working with a framepage. Have the dropdown in the left/right/top frame and load the info in another framepage. The code will be even easier, since the if then else can be dropped, there be less trafic and quicker responsetimes. (The dropdown just stays visible in one of the framepages, with the picked option selected)
    Last edited by raf; 04-24-2003 at 08:43 AM.

  • #5
    Abd
    Abd is offline
    New Coder
    Join Date
    Aug 2002
    Location
    Lagos, Nigeria
    Posts
    99
    Thanks
    0
    Thanked 0 Times in 0 Posts
    raf,

    pls I will need more detail on you

    -----------------------------------------------------------
    in the select tag, you need an onclick="submit();", and the method="post" and name="pagename
    ----------------------------------------------------------------

    can you help with the submit() function I mean the (code).

    Thanks
    Abdul
    Abdul

  • #6
    raf
    raf is offline
    Master Coder
    Join Date
    Jul 2002
    Posts
    6,589
    Thanks
    0
    Thanked 0 Times in 0 Posts
    Your right. This wasn't one of my clearest posts. Your code should look something like this:
    Code:
    <form name="FormName" action="pages.asp" method="post">
    <select name="catagory" size="1" onclick="submit();">
    First line = openingtag form. Second line: openingtag for the dropdownbox, with the javascriptcommand in it
    You need to replace the "pages.asp" en "catagory" with your pagename and name of the dropdownbox

    But it'd advice agains working this way (see previous post)

    If you use a frameset, you need to set the tartget in the form tag
    <form name="FormName" action="pages.asp" target="name of frame where to load the file" method="post">

  • #7
    Abd
    Abd is offline
    New Coder
    Join Date
    Aug 2002
    Location
    Lagos, Nigeria
    Posts
    99
    Thanks
    0
    Thanked 0 Times in 0 Posts
    thanks raf,

    I understand that;


    <script language="JavaScript">
    function Submit()
    {
    .
    .
    .
    .


    }

    but what I mean is what type code will be inside Submit()?

    Abd
    Abdul

  • #8
    raf
    raf is offline
    Master Coder
    Join Date
    Jul 2002
    Posts
    6,589
    Thanks
    0
    Thanked 0 Times in 0 Posts
    I understand that;
    No you don't Just try it like that. No extra code needed. It's magic ! Just
    <select name="catagory" size="1" onclick="submit();">
    But you'll see why this is not a good way to work. Actually, you should click on the arrow in the dropdown, hold the mouskey down, go to the value and then release it. otherwise, if you releas the mousebutton, the form will be submitted before you select a value by clicking on it. So you'll always have false hits etc. You can probably use doubleclick to submit, but then you'd have to write a small instruction near the dropdown etc, so it then would be easier to just add a submitutton or an arraw or whatever.

  • #9
    Abd
    Abd is offline
    New Coder
    Join Date
    Aug 2002
    Location
    Lagos, Nigeria
    Posts
    99
    Thanks
    0
    Thanked 0 Times in 0 Posts
    raf,

    Thanks for your patience, I have attached the frame screen with this thread, what am triyng to say briefly is

    1. select a number from the ComboBox in the left frame "Mobile No"
    2. Detail information from the database should be displayed in the right frame where you have "Left, Center, Right".

    Thanks
    Abd
    Attached Thumbnails Attached Thumbnails ComboBox Item Populating a Form-frame.gif  
    Abdul

  • #10
    raf
    raf is offline
    Master Coder
    Join Date
    Jul 2002
    Posts
    6,589
    Thanks
    0
    Thanked 0 Times in 0 Posts
    Abd,

    what exactly do you need? Not sure what you ask here.
    Do, you have the code to build the listbow and to select and display the info for the form? If so, just post it here and i'll build a frameset. But it's real basic html you'de should master if you want to write some bigger app's.

  • #11
    Regular Coder
    Join Date
    Jan 2003
    Posts
    867
    Thanks
    4
    Thanked 8 Times in 8 Posts
    I think you just need to specify the right frame as the target of the form where you are searching.

    <form name="FormName" action="pages.asp" method="post" target="your_right_frame">

    This will take the number from the left frame and send the results to the right frame.

  • #12
    Abd
    Abd is offline
    New Coder
    Join Date
    Aug 2002
    Location
    Lagos, Nigeria
    Posts
    99
    Thanks
    0
    Thanked 0 Times in 0 Posts
    yeah raf, I have the code to build the ComboBoxbox, but I do not have the code to select and display the information at the specified location. Bellow are the codes for, frameset, and building the ComboBox. So I pls need help in the code to select and display the information, you may just use few text fields for the display information.

    FRAMESET CODE (frm.asp)
    --------------------------------
    <html>
    <head>
    <title>Test</title>
    </head>

    <FRAMESET ROWS="15%,*">
    <FRAME SRC="net.html" NAME=TITLE SCROLLING=NO>

    <FRAMESET COLS="10%,*">
    <FRAME SRC="side.asp" NAME=SIDEBAR>
    <FRAME SRC="center.html" NAME=RECIPES>
    </FRAMESET>

    <NOFRAMES>
    <H1>Data</H1>

    <A HREF="recipes.html">no-frames</A> version.
    </NOFRAMES>

    </FRAMESET>


    </html>
    --------------------------------------------------------

    POPULATING COMBOBOX CODE(side.asp)
    -----------------------------------------

    <html>
    <head>
    <title>Test</title>
    </head>
    <body>

    <%
    Set oConn = Server.CreateObject("ADODB.Connection")
    oConn.open "PROVIDER=SQLOLEDB;DATA SOURCE=ABD;UID=sa;PWD=abd;DATABASE=abdul"

    Set rs=oConn.execute("Select DISTINCT phonenum from globacom")
    FName = RS.Fields("phonenum")


    response.write "<font face='arial'><b>Mobile No:</b></font>&nbsp;<select name='txtassignedto'>"&vbcrlf
    while not rs.eof
    response.write "<option value="""&rs("phonenum")&""">"&rs("phonenum")&"</option>"&vbcrlf
    rs.movenext
    wend
    response.write "</select>"&vbcrlf

    rs.close
    set rs=nothing
    oConn.close
    set oConn=nothing

    if request.form("action") = "Serrch" then
    Response.Redirect"csr1.asp"
    end if


    %>

    <form name="form1" action="csr1.asp" method="post" TARGET="RECIPES">
    <center><input type="submit" value="Search" name="action"></center>
    </form>



    </body>
    </html>



    I hope I made myself clear now
    Thanks raf
    Abdul

  • #13
    raf
    raf is offline
    Master Coder
    Join Date
    Jul 2002
    Posts
    6,589
    Thanks
    0
    Thanked 0 Times in 0 Posts
    Posts crossed.

    I'll post some pages later on (must do some other stuff first). Just some stuff i have lying around, but you'll have to customize it with your own data. It basically is just like any ordinary formpage you dynamically build and fill in.
    Last edited by raf; 04-24-2003 at 05:51 PM.

  • #14
    raf
    raf is offline
    Master Coder
    Join Date
    Jul 2002
    Posts
    6,589
    Thanks
    0
    Thanked 0 Times in 0 Posts
    OK. Now the page with the dropdown, you need to place the opening form-tag before the first formelement, so before the dropdown. And the form endtag should be after the submit button. Like

    Code:
    Set rs=oConn.execute("Select DISTINCT phonenum from globacom")
    FName = RS.Fields("phonenum") 
    %>
    <form name="form1" action="csr1.asp" method="post" TARGET="RECIPES">
    <%
    response.write "<font face='arial'><b>Mobile No:</b></font> <select name='txtassignedto'>"&vbcrlf 
    while not rs.eof 
    response.write "<option value="""&rs("phonenum")&""">"&rs("phonenum")&"</option>"&vbcrlf 
    rs.movenext 
    wend 
    response.write "</select>"&vbcrlf 
    rs.close 
    set rs=nothing 
    oConn.close 
    set oConn=nothing 
    
    if request.form("action") = "Serrch" then
    Response.Redirect"csr1.asp"
    end if
    
    
    %>
    
    <center><input type="submit" value="Search" name="action"></center>
    
    </form>
    
    
    
    </body>
    </html>
    bold = changed. Italic = what does it do? can't it be trown out?

    so now you need a page csr1.asp. This page will be loaded in the richt page.
    Ther you just make your select. Then have the form. It's always easier if you just create the form (without value, do the layout and stuf, and then you just put in the values. like
    Code:
    D1 : <input type="text" name="xxboordd1" size="4" value="<%=rsrecordsetname.Fields("boordd1")%>">&nbsp;mm<br />
    D2 : <input type="text" name="xxboordd2" size="4" value="<%=rsArtikels.Fields("boordd2")%>">&nbsp;mm<br />
    L1 : <input type="text" name="xxboordl1" size="4" value="<%=rsArtikels.Fields("boordl1")%>">&nbsp;mm<br />
    L2 : <input type="text" name="xxboordl2" size="4" value="<%=rsArtikels.Fields("boordl2")%>">&nbsp;mm<br />
    bold = the value from the recordset is set as the value for the textfield. Its just straigth html, with code snippets to paste in the values from the recordset.

  • #15
    Abd
    Abd is offline
    New Coder
    Join Date
    Aug 2002
    Location
    Lagos, Nigeria
    Posts
    99
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Question

    thanks raf,

    I have build the file csr1.asp, but when I ran it it give an error message " Object Required" at <b>First Name:</b>
    <input name="FirstName" type="text" value="<%=rs.Fields("firstname")%>"><br>

    Bellow is the complete code;
    <Html>
    <head><title>Return Data</title>
    </head>
    <body>
    <%
    Set oConn = Server.CreateObject("ADODB.Connection")
    oConn.open "PROVIDER=SQLOLEDB;DATA SOURCE=ABD=sa;PWD=abd;DATABASE=abdul"

    Set rs=oConn.execute("Select DISTINCT phonenum from glob ")

    rs.close
    set rs=nothing
    oConn.close
    set oConn=nothing

    %>

    <form name="form1" method="post" action="csr1.asp>
    <b>First Name:</b>
    &nbsp;<input name="FirstName" type="text" value="<%=rs.Fields("firstname")%>"><br>

    <b>Last Name:</b>
    &nbsp;<input name="lastname" type="text" value="<%=rs.Fields("lastname")%>" readonly><br>

    <b>Middle Name:</b>
    &nbsp;<input name="middlename" type="text"value="<%=rs.Fields("middlename")%>" readonly><br>

    <b>Home Address:</b>
    &nbsp;<input name="homeadd" type="text" size="17" value="<%=rs.Fields("homeadd")%>"><br>

    <font color="blue"><b>Phone Number:</b></font>
    &nbsp;<input name="phonenum" type="text" size="18" value="<%=rs.Fields("phonenum")%>"><br>

    <p align="center"><input type="submit" value="Submit">
    </form>
    </body>
    </html>

    -------------------------------------------------------
    But with the bellow code replacing the <input type=text;...............................>

    <input name="FirstName" type="text" value="<%=Server.HTMLEncode(firstname)%>">

    it works but display ONLY one record, if I select another number from the ComboBox it doesn't display, even if I hold down the mouse button. I am thinking may be the problem is moving withing the record set, can you pls help.

    Abd
    Abdul


  •  
    Page 1 of 2 12 LastLast

    Posting Permissions

    • You may not post new threads
    • You may not post replies
    • You may not post attachments
    • You may not edit your posts
    •