Library tutorials & articles
Remote Scripting With JavaScript and ASP
- Introduction
- What is remote scripting?
- Testing remote scripting
- Enabling remote scripting on the server side
- Another remote scripting example
- Conclusion
Another remote scripting example
Because we're working with JavaScript on the client and ASP on the server, we can put JavaScript's even handling methods and ADO on the server side to good use and create another remote scripting example.
We're going to create a HTML form that contains one text box and a list box. We will also create an SQL Server 2000 database that contains a list of people. When the user enters some text into the text box, we will capture this event using the onKeyUp event and use remote scripting to get a list of people from a database whose names contain the text entered into the text box.
Our example will use two files: people.html (which will hold the HTML form) and people.asp (which will retrieve the people from the database). Both files will implement remote scripting to make our example possible.
[Note] All of the files that are required for the examples displayed in this article are available for download from the support material for this article. [End Note]
Start by creating a new SQL Server 2000 database called people. Inside the people database, create a table called workers. Use query analyzer and the following code to do so (I am assuming that SQL Server 2000 is installed locally):
create database people
go
use people
go
create table workers
(
workerId int identity(1, 1) primary key,
firstName varchar(20),
lastName varchar(20),
)
After you've created the people database, add some records to the workers table:
insert into workers(firstName, lastName) values('Fred', 'Smith')
insert into workers(firstName, lastName) values('John', 'Fitzpatrick')
insert into workers(firstName, lastName) values('Roger', 'Eggerton')
insert into workers(firstName, lastName) values('Russell', 'Laugher')
insert into workers(firstName, lastName) values('Sally', 'Rushington')
insert into workers(firstName, lastName) values('Dorothy', 'Hurth')
insert into workers(firstName, lastName) values('Freida', 'Koolos')
insert into workers(firstName, lastName) values('Ronald', 'Jones')
insert into workers(firstName, lastName) values('Randal', 'Hughes')
insert into workers(firstName, lastName) values('Luke', 'Russell')
We're now ready to setup our HTML form. Create a file called people.html and enter the following code into it:
<html>
<head>
<title> Remote Scripting Example </title>
<script language="JavaScript" src="_ScriptLibrary/RS.HTM"></script>
<script language="JavaScript">
function findNames(theText)
{
if(theText != "")
{
var objRS = RSGetASPObject("people.asp");
var objResult = objRS.getPeople(theText, 5);
var strNames = objResult.return_value;
if(strNames != "undefined")
{
var arrNames = strNames.split("|");
document.frmPeople.names.length = 0
for(i = 0; i < arrNames.length-1; i++)
{
document.frmPeople.names.options[i] = new Option();
document.frmPeople.names.options[i].text = arrNames[i];
}
}
else
{
// No results found, clear the list
document.frmPeople.names.length = 0;
}
}
else
{
// No text entered, clear the list
for(i = 0; i < document.frmPeople.names.length-1; i++)
document.frmPeople.names.length = 0;
}
}
</script>
</head>
<body>
<h2> Find People </h2>
<form name="frmPeople" action="#" method="post">
<input onKeyUp="findNames(this.value)" type="text" maxlength="40" id="keyword" style="width:200"><br>
<select multiple size="5" id="names" name="names" style="width:200">
<option value="null">-- Enter Keywords Above --</option>
</select>
</form>
<script language="JavaScript">
RSEnableRemoteScripting("/_ScriptLibrary");
</script>
</body>
</html>
When the user enters any text in the text box, its onKeyUp event calls the JavaScript findNames function, passing its text value as the first argument to the findNames function. The second argument is 5, which tells our ASP function the maximum number of names to return.
We then use JavaScript and remote scripting to create an object from people.asp and we call that objects getPeople method, which returns a list of people separated by a pipe character ("|"). If a list has been returned then we split that list into an array and add each name to the drop down list.
Our people.html file is not too useful without its complementary people.asp file, so let's look at that now. Create a new file called people.asp and enter the following code into it:
<!--#INCLUDE FILE="_ScriptLibrary/RS.ASP"-->
<% RSDispatch %>
<script language="JavaScript" runat="server">
var public_description = new MainMethod();
function MainMethod()
{
this.getPeople = Function('searchString', 'maxRecords','return PeopleList(searchString, maxRecords)');
}
</script>
<script language="VBScript" runat="server">
function PeopleList(searchString, maxRecords)
on error resume next
dim conn
dim rs
dim names
set conn = server.createobject("ADODB.Connection")
set rs = server.createobject("ADODB.Recordset")
conn.open "provider=SQLOLEDB; Data Source=(local); Initial Catalog=people; UId=sa; Pwd="
rs.activeconnection = conn
rs.open "select top " + maxRecords + " firstName + ' ' + lastName as name from workers where firstName + ' ' + lastName like '%" & searchString & "%'"
while not rs.eof
names = names & rs("name") & "|"
rs.movenext
wend
PeopleList = names
end function
</script>
We've created one VBScript function called PeopleList. PeopleList accepts two arguments and returns a string variable. In this example we're passing in two arguments to our PeopleList function, so these are specified inside of our MainMethod constructor, like this:
this.getPeople = Function('searchString', 'maxRecords','return PeopleList(searchString, maxRecords)');
Taking a look at the JavaScript code in people.html, we can see that the function maps just nicely:
var objResult = objRS.getPeople(theText, 5);
There's nothing fancy about our PeopleList function: it simply connects to our SQL Server 2000 database, retrieves a list of people whose names are like the searchString argument and returns them as a list of separated values:
rs.open "select top " + maxRecords + " firstName + ' ' + lastName as name from workers where firstName + ' ' + lastName like '%" & searchString & "%'"
while not rs.eof
names = names & rs("name") & "|"
rs.movenext
wend
PeopleList = names
Loading people.html into my web browser, I played around with the remote scripting capabilities of our example. As I enter a different character into the text box, all records matching that text were returned and were automatically displayed in the list.
Related articles
Related discussion
-
Binary Studio | software development outsourcing Ukraine
by shane124 (4 replies)
-
.NET Developer in Ghana Required....
by sysview (0 replies)
-
Creating IFrame through javascript.
by cse_gurpreet (3 replies)
-
How to get unique Bytes from a String ?
by FarhanBajwa (0 replies)
-
GridView cell colour change
by viral.mat (1 replies)
Related podcasts
-
The Future of .NET Dotfuscator with Gabriel Torok
Keith and Woody sat down with PreEmptive President Gabriel Torok to discuss the news that Microsoft is including PreEmptive's Dotfuscator Community Edition in Visual Studio 2010. The guys also discussed how Dotfuscator can be used to assist with Feature Monitoring, Usage Expiry, and Tamper ...
Events coming up
-
Nov
20
Full Frontal JavaScript Conference
Brighton, United Kingdom
A one day JavaScript conference held in Brighton, UK whose essence is to discuss JavaScript "with nothing concealed or held back".The conference is being held at one of the world's first cinemas, which first opened in 1910.Speakers include...
i tried this it working in my local server (windows 2000). But when i uploaded these files on the internet server it showing an error message "OBJECT DOES NOT SUPPORT THIS PROPERTY OR METHOD". Do u know why this is happening.
kumar
cross browser remote scripting client
http://authors.aspalliance.com/thycotic/articles/view.aspx?id=4
sample asp.net application using remote scripting
http://www.thycotic.com/dotnet_remotescripting.html
-brian
I have read this article on Remote scripting with Asp. I am wondering
I have read this article on Remote scripting with Asp. I am wondering
if any support is there with Asp.Net. If there what are the relevant links to practice remote scripting with asp.net. Tx
I am trying some remote scripts. I am getting the same error "Failed to create the ASP object: url". I tried installing the JVM, but still i am receiving the error. I am pasting my code here for your reference. I will appreciate if you have any suggestions or comments,
The "snake.htm" calls snake.asp file from the server. The snake.asp and snake.htm are in the same folder on the server. I am running the client browser from the server machine.
<HTML>
<HEAD>
<TITLE>Remote Scripting Test</TITLE>
</HEAD>
<BODY>
<SCRIPT LANGUAGE="JavaScript" src="../_ScriptLibrary/RS.HTM"></SCRIPT>
<SCRIPT LANGUAGE="JavaScript">
RSEnableRemoteScripting("../_ScriptLibrary")
</SCRIPT>
<SCRIPT LANGUAGE="JavaScript" for="btnStraight" event="onclick">
snake = RSGetASPObject("snake.asp")
cycle = T1.value;
co = snake.TravelStraight(cycle);
</SCRIPT>
<SCRIPT LANGUAGE="JavaScript" for="btnStop" event="onclick">
snake = RSGetASPObject("snake.asp")
co = snake.STOP();
</SCRIPT>
<form name ="snake_frm">
<p>Enter the No of Cycles <input type="text" name="T1" size="5" tabindex="1"></p>
<p> </p>
<p>
<input type="button" value="STRAIGHT" name="btnStraight">
</p>
<p> <input type="button" value="Right" name="btnRight">
<input type="button" value="CENTER" name="btnCenter">
<input type="button" value="LEFT" name="btnLeft">
</p>
<p>
<input type="button" value="STOP" name="btnStop"></p>
<p> </p>
<p> </p>
<p> </p>
<p> </p>
<p> </p>
<p> </p>
<p> </p>
</form>
<p> </p>
<p> </p>
</body>
</html>
All I want to beable to do is have the Remote scripting return a matrix of the querry I submitted. I tried going through the tutorial on remote scripting step by step and can't get the List People SQL tutorial to work. Does anybody know how I can dynamically look up SQL Queries on the serverside and dynamically change my page on the server side?!
The tutorial just hangs never finds any of the users and locks the browser.
Thanks
Shep
It requires Microsoft VM to run and also though a very common thing which just slips of our mind - use "../folder/_scriptlibrary" in the client file .
This may be one of the reasons that its giving an error "Object doesn't support this property or method"
Hi Anil,
This looks like solution to my problem,
Romote scripting which was working suddenly stopped working don't know the reason. probably the JVM got changed sometime back Thanks alot. I will try changing JVM....to remote scripting...
thanks again
Amit.
I had been struggling
I spent 4-5 hours and then came back the next day and it struck
For you guys who're struggling to get Remote Scripting to work, try this and see if it works for you!
Anil
I got the same error i had to change the path from
<script language="JavaScript">
RSEnableRemoteScripting("/_ScriptLibrary");
</script>
to
<script language="JavaScript">
RSEnableRemoteScripting("_ScriptLibrary");
</script>
and it worked
The article is great but when I run this I get an error saying failed to create object "people.asp"
I am running win2kserver sp3/visual idev 6 sp5
Thanks
Jack
Install SP1 for Win XP.
Due to litigation matters, JVM was not included in the release of XP (with IE6), but is now finally available in SP1.
regards,
KH
hi there,
hey did you able to run "remote scripting with javascript and asp" tutorial successfully ? if so, pl help me in that.
Thanks,
viral shah.
Hello
I had similar errors to those that you mentioned, i noticed that they occured soon after i had installed the sun jvm, after much head scratching and even altering rs.htm it dawned on me that perhaps the new jvm might be the reason and that i might not have any problems if i used microsofts jvm instead, i dont know if this is for sure, but when i disabled the sun jvm i didn't have any more of the problems that i had, which happen to be very similar to you own
I have in c:\inetpub\wwwroot\test\catalog\config\test.asp which uses the remote scripting by adding this
lines to the code
<body>
....
....
<!-- Incluir para Remote Scripting -->
<script language="JavaScript" src="../../ScriptLibrary/rs.htm"></script>
<script language="JavaScript">RSEnableRemoteScripting("../../ScriptLibrary");</script>
<!---->
</body>
And it stills gives me the same error:"Object doesn't support this property or method" with a line number not matching a line in the code.
What can I do? I have tried to re-install the rs files and it sill didn't work, what else can I do?
amitmathur23, you have to install the "Remote Scripting 1.0b" for resolve it...
"Object doesn't support this property or method".
When i debeg it, it is found on rs.htm file and on the line where
"this.rsapplet.startRequest(request.id,url_context,url,this.REQUEST_MODE_COMPLETE);" is mentioned.
Please help.
I have tried to run the samples on your article on RS and none of them work. I get an error when RSGetASPObject is invoked.
The problem is in this method MSRSstartRequest. The msg say Object does not support property or method was not handled. Is there something that I'm missing. I using InterDev 6 on Win2k SP2. Pls Help
you can contact the author at mitchell@devarticles.com (sorry ... that information should be present in his profile)
Hi,
The article is very good. But I have got a small problem. Whom do i Contact for further queries.
Can the author look into the quries or problems if the users like me has some problems.
Please let us know.
Regards,
Sailendra.
email:tirusail@yahoo.com
This thread is for discussions of Remote Scripting With JavaScript and ASP.