Results 1 to 9 of 9

Thread: get text with out skip/refresh the page

  1. #1

    Thread Starter
    Fanatic Member
    Join Date
    Oct 2001
    Location
    Earth
    Posts
    762

    get text with out skip/refresh the page

    hi

    i have two text box in a page. one
    name:
    ID
    Name

    when a user enter a ID and click Go button the page get the name from database and show in Name column

    i want the name comes in text box from Database with out refresh the page...

    is there any way to do it???

  2. #2
    Hyperactive Member Anglo Saxon's Avatar
    Join Date
    Mar 2002
    Location
    Durham, UK
    Posts
    259
    Look at remote scripting :

    http://msdn.microsoft.com/library/en...ting041299.asp


    ---
    Anglo Saxon

  3. #3
    Lively Member
    Join Date
    May 2001
    Location
    Fredericton, NB, Canada
    Posts
    85
    You would have to retrieve the data for every single user and store it in a client side array and filter through that array when the user enters an id...

    not necessarily recommended if user data is sensitive.

  4. #4

    Thread Starter
    Fanatic Member
    Join Date
    Oct 2001
    Location
    Earth
    Posts
    762

    Cool

    thanks for replay....


    i read the artical
    http://msdn.microsoft.com/library/e...pting041299.asp

    it's complex...

    I think it using jscript...
    i just want to use ASP and javascript......

    i m still waiting

  5. #5
    Hyperactive Member Anglo Saxon's Avatar
    Join Date
    Mar 2002
    Location
    Durham, UK
    Posts
    259
    Then you will have to use the method that PunkRockNeil suggested , you will need to take note that this is a very unsecure way of achieving what you want !:
    Code:
    <%option explicit%>
    <html>
    <head>
    <title>Untitled</title>
    <script>
    <!--
    <%
    dim objConn, objRS, strSQL,conString,strID,strNames
    
    conString="Driver={SQL Server};Server=(local);UID=;PWD=;Database=YOURDATABASE;"
    
    	set objConn = server.createobject("ADODB.Connection")
    	objConn.ConnectionString = conString
    	objConn.open
    				
    	strSQL = "SELECT id,name FROM users ORDER BY user_name"
    	set objRS = objConn.execute(strSQL)
    	
    	if not objRS.eof then
    		do while not objRS.eof
    			strID = strID & objRS("id") & ","
    			strNames = strNames & "'" & objRS("name") & "',"
    		objRS.movenext
    		loop
    	end if
    
    'strip off trailing commas
    strID = left(strID,len(strID)-1)
    strNames = left(strNames,len(strNames)-1)
    'write out javascript array info
    '**UNCOMMENT THESE LINES**
    'Response.Write "var IDList = new Array(" & strID & ");" & vbCrLf
    'Response.Write "var NameList = new Array(" & strNames & ");" & vbCrLf
    %>
    //THIS IS AN EXAMPLE OF WHAT SHOULD BE GENERATED BY THE ASP CODE!!
    //REMOVE THESE LINES WHEN YOU ARE RUNNING THE CODE ABOVE
    var IDList = new Array(128,124,125,123,127,126);
    var NameList = new Array('Fred Flintstone','Peter Pan','Mickey Mouse','Dan Dare','Spiderman','Goofy');
    
    
    function SearchIDList(ID){
    	var counter = 0;	
    	var IDCount = IDList.length;
    		for(counter=0;counter<IDCount;counter++){
    			if(ID == IDList[counter]){
    				return NameList[counter];
    			}
    		}
    alert("User not found!");
    return '';
    }
    //-->
    </script>	
    </head>
    <body>
    <form name="form1" action="">
    ID : <input type="text" name="id">
    <input type="button" onclick="document.form1.user_name.value=SearchIDList(document.form1.id.value);" value="search"><br>
    User Name : <input type="text" name="user_name">
    </form>
    </body>
    </html>

    ---
    Anglo Saxon
    Last edited by Anglo Saxon; Apr 7th, 2003 at 03:12 AM.

  6. #6
    Lively Member
    Join Date
    Jul 2002
    Location
    Mississippi
    Posts
    87
    Remote Scripting does get a little "involved" but if you ever learn it you will find a whole lot more uses for it. I'm glad I took the time to learn it.

  7. #7

    Thread Starter
    Fanatic Member
    Join Date
    Oct 2001
    Location
    Earth
    Posts
    762
    Originally posted by Anglo Saxon
    Then you will have to use the method that PunkRockNeil suggested , you will need to take note that this is a very unsecure way of achieving what you want !:
    Code:
    <%option explicit%>
    <html>
    <head>
    <title>Untitled</title>
    <script>
    <!--
    <%
    dim objConn, objRS, strSQL,conString,strID,strNames
    
    conString="Driver={SQL Server};Server=(local);UID=;PWD=;Database=YOURDATABASE;"
    
    	set objConn = server.createobject("ADODB.Connection")
    	objConn.ConnectionString = conString
    	objConn.open
    				
    	strSQL = "SELECT id,name FROM users ORDER BY user_name"
    	set objRS = objConn.execute(strSQL)
    	
    	if not objRS.eof then
    		do while not objRS.eof
    			strID = strID & objRS("id") & ","
    			strNames = strNames & "'" & objRS("name") & "',"
    		objRS.movenext
    		loop
    	end if
    
    'strip off trailing commas
    strID = left(strID,len(strID)-1)
    strNames = left(strNames,len(strNames)-1)
    'write out javascript array info
    '**UNCOMMENT THESE LINES**
    'Response.Write "var IDList = new Array(" & strID & ");" & vbCrLf
    'Response.Write "var NameList = new Array(" & strNames & ");" & vbCrLf
    %>
    //THIS IS AN EXAMPLE OF WHAT SHOULD BE GENERATED BY THE ASP CODE!!
    //REMOVE THESE LINES WHEN YOU ARE RUNNING THE CODE ABOVE
    var IDList = new Array(128,124,125,123,127,126);
    var NameList = new Array('Fred Flintstone','Peter Pan','Mickey Mouse','Dan Dare','Spiderman','Goofy');
    
    
    function SearchIDList(ID){
    	var counter = 0;	
    	var IDCount = IDList.length;
    		for(counter=0;counter<IDCount;counter++){
    			if(ID == IDList[counter]){
    				return NameList[counter];
    			}
    		}
    alert("User not found!");
    return '';
    }
    //-->
    </script>	
    </head>
    <body>
    <form name="form1" action="">
    ID : <input type="text" name="id">
    <input type="button" onclick="document.form1.user_name.value=SearchIDList(document.form1.id.value);" value="search"><br>
    User Name : <input type="text" name="user_name">
    </form>
    </body>
    </html>

    ---
    Anglo Saxon

    if i use this code then the latest data will not appear on javascript array

    for example

    at the time 8:10
    user A : open the page of item he enter code 99 the desc appear in a text box but no details appear bcoz the 99 code does not exist

    at the time 8:11
    user B open a page and enter the code 99 and it's detail and save the page

    now user a was unable to see the detials bcoz it enter after a minute ..........

  8. #8
    Fanatic Member davebat's Avatar
    Join Date
    Dec 2002
    Posts
    727
    just cheat and submit form to same page, so when the button is clicked it will load the same page with the box filled. if your database is small it should do it quick enough to look instantaneous

  9. #9

    Thread Starter
    Fanatic Member
    Join Date
    Oct 2001
    Location
    Earth
    Posts
    762
    thanks to all

Posting Permissions

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



Click Here to Expand Forum to Full Width