|
-
Apr 4th, 2003, 07:54 AM
#1
Thread Starter
Fanatic Member
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???
-
Apr 4th, 2003, 09:51 AM
#2
Hyperactive Member
-
Apr 4th, 2003, 09:51 AM
#3
Lively Member
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.
-
Apr 5th, 2003, 01:43 AM
#4
Thread Starter
Fanatic Member
-
Apr 7th, 2003, 03:08 AM
#5
Hyperactive Member
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.
-
Apr 7th, 2003, 11:37 AM
#6
Lively Member
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.
-
Apr 15th, 2003, 06:16 AM
#7
Thread Starter
Fanatic Member
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 ..........
-
Apr 15th, 2003, 06:31 AM
#8
Fanatic Member
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
-
Apr 16th, 2003, 04:10 AM
#9
Thread Starter
Fanatic Member
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|