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.
Results 1 to 10 of 10
  1. #1
    New Coder
    Join Date
    Feb 2006
    Posts
    26
    Thanks
    0
    Thanked 0 Times in 0 Posts

    display record automatically

    I have a form that includes 2 text input. I'd like the second text input to fill with the value selected from database based on the first textbox value, by default when I press enter or tab key. What methods should I look into to learn to do this?

    my database name:supplier_head
    it contains:supplier_name, supplier_code

    my asp form:
    Supplier Code:
    <input name="suppliercode" type="text" id="suppliercode">
    Supplier Name:
    <input type="text" id="textname" name="suppliername">

    so, my actual problem is:
    when i enter or key in the supplier code value, supplier name will appear at the next textbox (suppliername) which the value will be display based on value i enter on supplier code...

    so, what is the best way can i do to make this thing happen...

  • #2
    Regular Coder Baleric's Avatar
    Join Date
    Feb 2005
    Location
    Australia
    Posts
    332
    Thanks
    0
    Thanked 0 Times in 0 Posts
    so u want the 1st textbox 2 equal the 2nd textbox,
    so wen u type in the 1st its also shown in the second?

  • #3
    New Coder
    Join Date
    Feb 2006
    Posts
    26
    Thanks
    0
    Thanked 0 Times in 0 Posts
    the 2nd textbox value is based on the 1st textbox.
    for example: when i key in the first textbox (supplier code)=0001, the 2nd textbox (supplier name=eric) will display with the value which it retrieve from database.

  • #4
    New Coder
    Join Date
    Jul 2002
    Location
    UK
    Posts
    92
    Thanks
    0
    Thanked 0 Times in 0 Posts
    You'd have to have some kind of submit after the first box is entered to redirect to thatpage.asp?suppliercode=0001
    Then use that to generate an sql statment to get the supplier name.

    Or if there aren't too many suppliers in the database you could save some refershing and use ASP to generate some JavaScript with the suppliers name so that when the top box is filled the bottom box can be automatically populated without refreshing the page.

  • #5
    Senior Coder
    Join Date
    Nov 2002
    Location
    North-East, UK
    Posts
    1,265
    Thanks
    0
    Thanked 0 Times in 0 Posts
    You can use Ajax
    http://computer-helpforum.com/asp/aj...ulate_form.asp

    Basically you are using a query string to select records and then using Ajax to include the results in your page.

    Here is a basic Ajax tutorial
    http://www.dynamicdrive.com/dynamici...jaxcontent.htm
    PHP Code:
    <%@LANGUAGE="VBSCRIPT" CODEPAGE="1252"%>
    <!--
    #include file="db.asp" -->
    <%
    Dim Recordset1
    Dim Recordset1_numRows

    Set Recordset1 
    Server.CreateObject("ADODB.Recordset")
    Recordset1.ActiveConnection conn
    Recordset1
    .Source "SELECT user_name FROM ajax_user"
    Recordset1.CursorType 0
    Recordset1
    .CursorLocation 2
    Recordset1
    .LockType 1
    Recordset1
    .Open()

    Recordset1_numRows 0
    %>
    <%
    Dim Repeat1__numRows
    Dim Repeat1__index

    Repeat1__numRows 
    = -1
    Repeat1__index 
    0
    Recordset1_numRows 
    Recordset1_numRows Repeat1__numRows
    %>
    <!
    DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
    <
    html>
    <
    head>
    <
    meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1">
    <
    title>Populate textfield via AJAX</title>
    <
    script type="text/javascript">

    /***********************************************
    * Dynamic Ajax Content-  Dynamic Drive DHTML code library (www.dynamicdrive.com)
    * This notice MUST stay intact for legal use
    * Visit Dynamic Drive at http://www.dynamicdrive.com/ for full source code
    ***********************************************/

    var loadedobjects=""
    var rootdomain="http://"+window.location.hostname

    function ajaxpage(urlcontainerid){
    var 
    page_request false
    if (window.XMLHttpRequest// if Mozilla, Safari etc
    page_request = new XMLHttpRequest()
    else if (
    window.ActiveXObject){ // if IE
    try {
    page_request = new ActiveXObject("Msxml2.XMLHTTP")

    catch (
    e){
    try{
    page_request = new ActiveXObject("Microsoft.XMLHTTP")
    }
    catch (
    e){}
    }
    }
    else
    return 
    false
    page_request
    .onreadystatechange=function(){
    loadpage(page_requestcontainerid)
    }
    page_request.open('GET'urltrue)
    page_request.send(null)
    }

    function 
    loadpage(page_requestcontainerid){
    if (
    page_request.readyState == && (page_request.status==200 || window.location.href.indexOf("http")==-1))
    document.getElementById(containerid).value=page_request.responseText
    }
    </script>
    <script type="text/javascript">
    /***Combo Menu Load Ajax snippet**/
    function ajaxcombo(selectobjID, loadarea){
    var selectobj=document.getElementById? document.getElementById(selectobjID) : ""
    if (selectobj!="")
    //alert('populate_form_getEmail.asp?name=' + selectobj.value + ', ' + loadarea)
    ajaxpage('populate_form_getEmail.asp?name=' + selectobj.value, loadarea)
    }
    </script>
    <style type="text/css">
    <!--
    .style2 {font-size: small}
    -->
    </style>
    </head>

    <body>
    <form name="form1" method="post" action="">
      <p>Name 
        <input name="name" type="text" id="name" onblur="ajaxcombo('name','email')">
        (<% 
    While ((Repeat1__numRows <> 0) AND (NOT Recordset1.EOF)) 
    %>
        <%=(Recordset1.Fields.Item("user_name").Value)%>, 
        <% 
      Repeat1__index=Repeat1__index+1
      Repeat1__numRows=Repeat1__numRows-1
      Recordset1.MoveNext()
    Wend
    %>
        )
        &lt;- Valid user names <br>
        <span class="style2">*Type name then press tab to switch focus </span></p>
      <p>Email 
        <input name="email" type="text" id="email" value="">
    </p>
    </form>
    </body>
    </html>
    <%
    Recordset1.Close()
    Set Recordset1 = Nothing
    %> 

    The Ajax code calls the script
    Code:
    ajaxpage('populate_form_getEmail.asp?name=' + selectobj.value
    PHP Code:
    <!--#include file="db.asp" -->
    <%
    Dim email__MMColParam
    email__MMColParam 
    "1"
    If (Request.QueryString("name") <> ""Then 
      email__MMColParam 
    Request.QueryString("name")
    End If

    Dim email
    Dim email_numRows

    Set email 
    Server.CreateObject("ADODB.Recordset")
    email.ActiveConnection conn
    email
    .Source "SELECT user_email FROM ajax_user WHERE user_name = '" Replace(email__MMColParam"'""''") + "'"
    email.CursorType 0
    email
    .CursorLocation 2
    email
    .LockType 1
    email
    .Open()

    email_numRows 0

    If Not email.EOF Or Not email.BOF Then
     Response
    .Write(email.Fields.Item("user_email").Value)
    Else 
        
    Response.Write("")
    End If  end Not email.EOF Or NOT email.BOF

    email
    .Close()
    Set email Nothing
    %> 

  • #6
    New Coder
    Join Date
    Feb 2006
    Posts
    26
    Thanks
    0
    Thanked 0 Times in 0 Posts
    tq..it's work..

  • #7
    New Coder
    Join Date
    Feb 2006
    Posts
    26
    Thanks
    0
    Thanked 0 Times in 0 Posts
    tq degsy.my first problem has been solve using your coding..

    another problem is..

    I have the same form but i'd like the second and third text input o fill with the value selected from database based on the first textbox value, by default when I press enter or tab key.

    my database name:supplier_head
    it contains:supplier_name, supplier_code, supplier_type

    my asp form:
    Supplier Code:
    <input name="suppliercode" type="text" id="suppliercode">
    Supplier Name:
    <input type="text" id="textname" name="suppliername">
    Supplier type:
    <input type="text" id="suppliertype" name="suppliertype">

    so, my actual problem is:
    when i enter or key in the supplier code value, supplier name and supplier type will appear at the next textbox (suppliername and supplier type) which the value will be display based on value i enter on supplier code...

    can u help me???

  • #8
    Senior Coder
    Join Date
    Nov 2002
    Location
    North-East, UK
    Posts
    1,265
    Thanks
    0
    Thanked 0 Times in 0 Posts
    To populate two boxes you will have to change the AJAX method.

    I would create a dummy form within the Ajax page and include that.

    e.g.
    http://computer-helpforum.com/asp/aj...late_form2.asp

    populate_form2.asp
    Code:
    <%@LANGUAGE="VBSCRIPT" CODEPAGE="1252"%>
    <!--#include file="db.asp" -->
    <%
    Dim valid_names
    Dim valid_names_numRows
    
    Set valid_names = Server.CreateObject("ADODB.Recordset")
    valid_names.ActiveConnection = conn
    valid_names.Source = "SELECT user_name FROM ajax_user"
    valid_names.CursorType = 0
    valid_names.CursorLocation = 2
    valid_names.LockType = 1
    valid_names.Open()
    
    valid_names_numRows = 0
    %>
    <%
    Dim Repeat1__numRows
    Dim Repeat1__index
    
    Repeat1__numRows = -1
    Repeat1__index = 0
    valid_names_numRows = valid_names_numRows + Repeat1__numRows
    %>
    <!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
    <html>
    <head>
    <meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1">
    <title>Populate Form 2</title>
    <script type="text/javascript">
    
    /***********************************************
    * Dynamic Ajax Content- &#169; Dynamic Drive DHTML code library (www.dynamicdrive.com)
    * This notice MUST stay intact for legal use
    * Visit Dynamic Drive at http://www.dynamicdrive.com/ for full source code
    ***********************************************/
    
    var loadedobjects=""
    var rootdomain="http://"+window.location.hostname
    
    function ajaxpage(url, containerid){
    var page_request = false
    if (window.XMLHttpRequest) // if Mozilla, Safari etc
    page_request = new XMLHttpRequest()
    else if (window.ActiveXObject){ // if IE
    try {
    page_request = new ActiveXObject("Msxml2.XMLHTTP")
    } 
    catch (e){
    try{
    page_request = new ActiveXObject("Microsoft.XMLHTTP")
    }
    catch (e){}
    }
    }
    else
    return false
    page_request.onreadystatechange=function(){
    loadpage(page_request, containerid)
    }
    page_request.open('GET', url, true)
    page_request.send(null)
    }
    
    function loadpage(page_request, containerid){
    if (page_request.readyState == 4 && (page_request.status==200 || window.location.href.indexOf("http")==-1))
    document.getElementById(containerid).innerHTML=page_request.responseText
    }
    </script>
    </head>
    
    <body>
    <form name="form1" method="post" action="">
      <p>Name: 
        <input name="name" type="text" id="name" onKeyUp="ajaxpage('populate_form2_getDetails.asp?user_name=' + this.value,'details')">
        <% 
    While ((Repeat1__numRows <> 0) AND (NOT valid_names.EOF)) 
    %>
        <%=(valid_names.Fields.Item("user_name").Value)%> , 
        <% 
      Repeat1__index=Repeat1__index+1
      Repeat1__numRows=Repeat1__numRows-1
      valid_names.MoveNext()
    Wend
    %>
        <br>
      *type a name from the list</p>
      <p>
      
      <span id="details">
       Email:
        <input name="email" type="text" id="email">
        <br>
        Id:
        <input name="textfield" type="text" size="3">
    	</span>
      </p>
    </form>
    </body>
    </html>
    <%
    valid_names.Close()
    Set valid_names = Nothing
    %>

    populate_form2_getDetails.asp
    (e.g. populate_form2_getDetails.asp?user_name=paul)
    Code:
    <%@LANGUAGE="VBSCRIPT" CODEPAGE="1252"%>
    <!--#include file="db.asp" -->
    <%
    Dim getDetails__MMColParam
    getDetails__MMColParam = "1"
    If (Request.QueryString("user_name") <> "") Then 
      getDetails__MMColParam = Request.QueryString("user_name")
    End If
    %>
    <%
    Dim getDetails
    Dim getDetails_numRows
    
    Set getDetails = Server.CreateObject("ADODB.Recordset")
    getDetails.ActiveConnection = conn
    getDetails.Source = "SELECT user_email, user_id FROM ajax_user WHERE user_name = '" + Replace(getDetails__MMColParam, "'", "''") + "'"
    getDetails.CursorType = 0
    getDetails.CursorLocation = 2
    getDetails.LockType = 1
    getDetails.Open()
    
    getDetails_numRows = 0
    %>
    <% If Not getDetails.EOF Or Not getDetails.BOF Then %>
    Email:
    <input name="email" type="text" id="email" value="<%=(getDetails.Fields.Item("user_email").Value)%>">
        <br>
        Id:
        <input name="textfield" type="text" size="3" value="<%=(getDetails.Fields.Item("user_id").Value)%>">
        <% End If ' end Not getDetails.EOF Or NOT getDetails.BOF %>
       
        <% If getDetails.EOF And getDetails.BOF Then %>
    Email:
    <input name="email" type="text" id="email" value="">
    <br>
    Id:
    <input name="textfield" type="text" size="3" value="">
    <% End If ' end getDetails.EOF And getDetails.BOF %>
    
    <%
    getDetails.Close()
    Set getDetails = Nothing
    %>

  • #9
    New Coder
    Join Date
    Feb 2006
    Posts
    26
    Thanks
    0
    Thanked 0 Times in 0 Posts
    tq degsy.your coding successfully works.

    i have another problem regarding this topic.
    from the first situation, I have the same form but i'd like the second and third text input o fill with the value selected from database based on the first textbox value, by default when I press enter or tab key.
    how if the second text input(suppliername) fill with 2 value selected from database(supplier_firstname and supplier_lastname)

    my database name:supplier_head
    it contains:supplier_firstname,supplier_lastname, supplier_code, supplier_type

    my asp form:
    Supplier Code:
    <input name="suppliercode" type="text" id="suppliercode">
    Supplier Name:
    <input type="text" id="textname" name="suppliername">
    Supplier type:
    <input type="text" id="suppliertype" name="suppliertype">

    please help me if you have any idea..tq

  • #10
    Senior Coder
    Join Date
    Nov 2002
    Location
    North-East, UK
    Posts
    1,265
    Thanks
    0
    Thanked 0 Times in 0 Posts
    That is what the example shows.

    It is a different example to the first one
    http://computer-helpforum.com/asp/aj...late_form2.asp

    Again, you need to change your queries to suit, but it is doing what you asked.
    Type a name in to the box and it will populate the other two.


  •  

    Posting Permissions

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