This example shows how to display a header-detail form using remote scripting. It gives us the chance to navigate through the records with next, previous, move first and move last.This example shows how to display a header-detail form using remote scripting. It gives us the chance to navigate through the records with next, previous, move first and move last.This method is particularly useful when we need to quickly scroll through a number of records. This example shows some basic navigation techniques but more functionality could be added by simply calling a different function from the client side to update or delete the current record.To see this example working please check www.houndware.com/dario/remote.aspThis is the client page. I used the pubs database to get each author and display every book written by her/ him. Client side ---Remote.asp
===============================================================
<!--#include file = "../ADOVBS.INC"-->
<HTML><HEAD>
<TITLE>Remote Scripting Example</TITLE>
<SCRIPT Language="JavaScript" src="../_ScriptLibrary/rs.htm"></SCRIPT>
<!-- enable remote scripting -->
<script language="JavaScript">RSEnableRemoteScripting("../_ScriptLibrary");</script>
<script language="JavaScript">
// declare variables
var serverURL = "RemoteAction.asp";
var intcount =0 ;
var intLastTran =1 ;
function firstTran()
{
intcount=1 ;
getRemoteData (intcount );
}
function lastTran()
{
intcount= intLastTran;
getRemoteData(intcount);
}
function previousTran()
{
if (intcount < 2 )
{
alert ( "You have reached the begining ");
}
else
{
intcount = intcount -1 ;
getRemoteData(intcount);
}
}
function nextTran()
{
if ( intLastTran <= intcount )
{
alert ("You have reached the end ");
}
else
{
intcount = intcount + 1;
getRemoteData(intcount);
}
}
function getRemoteData( intcount )
{
status="Getting record...";
// call server-side function with the page name , funcion and parameter
// NOTE: if more parameters need to be passed, simply add them to the string
// ie: co=RSExecute(serverURL,"getRemoteData",param1,param2,param3,..);
co=RSExecute(serverURL,"getRemoteData",intcount);
var row;
var detail ;
var trandata;
var a ;
var trandata = new Array() ;
// create an array with each row as an element
row = co.return_value.split(";;");
DataTran.innerText=""; // clear the previous value
detail = "<table width=100% cellspacing=0><tr background=silver><td width=10% ><strong>Title ID</strong></td><td width=40% ><strong>Title</strong></td><td width=5% ><strong>Type</strong></td><td width=7% ><strong>Price</strong></td><td width=7% ><strong>Advance</strong></td>";
for (var i=0; i < row.length ; i++ )
{
col = row[i].concat();
col= col.split(";");
trandata[i]= new Array();
detail = detail + "<tr>" ;
for (var a=0 ;a < col.length ; a++)
{
trandata[i][a]= col[a]; // setting the column value into the array
if ( a > 6 )
{
detail= detail + "<td>" + trandata[i][a] + "</td>" ;
}
}
detail = detail + "</TR>" ;
}
DataTran.innerHTML = detail ;
document.all.FirstName.value=trandata[0][0];
document.all.LastName.value=trandata[0][1];
document.all.Phone.value=trandata[0][2];
document.all.City.value=trandata[0][3];
document.all.State.value=trandata[0][4];
document.all.Zip.value=trandata[0][5];
intLastTran = trandata[0][6];
status="Done";
}
</script >
</head>
<body bgcolor="#c9cbc0" alink=white vlink=white>
<table width=90% border=1 bgcolor=silver bordercolordark=Black>
<tr ><td colspan=10> <table bgcolor=336699 width=100%><tr><td width=75% ><font size=6 color=white >Remote Scripting Example </font><font color=white size=3> by <a href=mail:dmedele@houndware.com> Dario Medele</a></font></td>
<td>
<a href="Javascript:lastTran()" > Last Record</a>
<a href="Javascript:nextTran()" > Next Record</a>
<a href="Javascript:previousTran()" >Previous Record </a>
<a href="Javascript:firstTran()" >First Record </a>
</td></tr></table>
</td></tr>
<tr><td colspan =10>
<table width=100% cellspacing=0 bordercolordark="black">
<tr ><td valign=bottom><strong>First Name</strong></td><td>
<input type= text name=FirstName value="">
</td></tr>
<tr ><td><strong>Last Name</strong></td><td>
<input type= text name=LastName value="">
</td>
</td></tr>
<tr><td><strong>Phone</strong></td> <td>
<input type= text name=Phone value=""> </td>
</tr><tr><td><strong>City</strong></td><td>
<input type = text name=City value="">
</td></tr>
<tr><td><strong>State</strong></td><td>
<input type = text name=State value="">
</td></tr>
<tr><td><strong>Zip</strong></td><td>
<input type = text name=Zip value="">
</td></tr>
</table>
</td></tr>
<tr><td colspan =10>
<table width ="100%" border="1" bordercolordark="Black">
<tr bgcolor=336699 ><td colspan=10> <table width=100%><tr><td width=50% ><font color=white ><strong>Titles</strong></font></td><td>
</td></tr></table><tr><td colspan=10 >
<DIV ID="Detail">
<p ID="DataTran"></p>
</DIV>
</td></tr>
</td></tr><tr><td>
</td></tr></table>
</BODY>
</HTML>
End of client side
===============================================================
Server side -- RemoteAction.asp
<%@ LANGUAGE=VBSCRIPT %>
<% RSDispatch %>
<!--#include file = "../ADOVBS.INC"-->
<!--#include file="../_ScriptLibrary/rs.asp"-->
<html>
<head>
<title>SiS</title>
<SCRIPT RUNAT=SERVER Language=javascript>
function Description()
{
this.getRemoteData= Function('intcount','return getRemoteData(intcount)');
}
public_description = new Description();
</SCRIPT>
<SCRIPT RUNAT=SERVER Language=VBScript >
function getRemoteData(intcount )
// This sql string is made of the elements of the header, the total number of records in the header ,
// and the details. Also the parameter passed (intcount) will indicate which record the client requested
strsql = " select a.au_fname, a.au_lname, a.phone, a.city , a.state,a.zip, (select count(*) from authors ) as total, isnull(t.title_id,'_')as title_id ,isnull(t.title,'_') as title " &_
" , isnull(t.type,'_') as type ,isnull(convert(varchar(100),t.price),'_')as price ,isnull(convert(varchar(100),t.advance),'_') as advance " &_
" from authors a left " &_
" join titleauthor ta on a.au_id = ta.au_id " &_
" left join titles t on ta.title_id = t.title_id " &_
" where a.au_id in " &_
" ( select top 1 au_id from authors where au_id in ( select top " & intcount & " au_id " &_
" from authors order by au_fname asc ) order by au_fname desc ) " &_
" order by au_fname asc "
strconn = "Driver={SQL Server};Description=SIS;SERVER=111.111.111.111;UID=sa;PWD=;DATABASE=pubs"
set rs= server.CreateObject("ADODB.Recordset")
rs.Open strsql,strconn, adOpenStatic,adLockOptimistic
if rs.eof and rs.bof then
strTemp= "No data found"
else
// separate rows using ";;" and columns using ";"
strTemp = rs.Getstring(,,";",";;")
end if
// asign the string to the function
getRemoteData = strTemp
rs.Close
set rs.ActiveConnection = nothing
set rs = nothing
end function
</script>
</head>
<body>
</body>
</html>
end of server side
| DISCLAIMER: The content provided in this article is not warranted or guaranteed by Developer Shed, Inc. The content provided is intended for entertainment and/or educational purposes in order to introduce to the reader key ideas, concepts, and/or product reviews. As such it is incumbent upon the reader to employ real-world tactics for security and implementation of best practices. We are not liable for any negative consequences that may result from implementing any information covered in our articles or tutorials. If this is a hardware review, it is not recommended to open and/or modify your hardware. |
More Code Examples Articles More By aspfree developerWorks - FREE Tools! | You'll get answers to many questions and more from David Barnes, Lead Evangelist for IBM Emerging Internet Technologies. David will discuss aspects of Web 2.0 that bring value to corporations, academia, and government. He'll also discuss IBM's vision around Web 2.0, including the importance of remixability and consumability. The discussion will culminate with examples of various IBM Software Group solutions you can use to get ahead of the Web 2.0 adoption curve. FREE! Go There Now!
| | | | As businesses grow increasingly dependent upon Web applications to provide services to customers, employees and partners, these complex applications become more difficult to secure. Although traditional security solutions protect Internet infrastructure layers, they do not guard against HTTP and HTML attacks. Many organizations that conduct security testing still deploy applications that allow attackers to manipulate their logic and wreak havoc on their business. To mitigate this risk, development and delivery teams must address Web application security throughout the lifecycle, addressing the many layers detailed in this paper. FREE! Go There Now!
| | | | This whitepaper presents the benefits of successfully introducing static analysis into your organization using IBM Rational Software Analyzer. Additionally, it identifies some common pitfalls that can hinder the effective use of static analysis tooling as well as presents 10 simple strategies designed to help you quickly realize the value of static analysis using Rational Software Analyzer. FREE! Go There Now!
| | | | Visit IBM developerWorks to download IBM DB2 Express-C 9.5, a no-charge version of DB2 Express 9 database server. DB2 Express-C offers the same core data server base features as other DB2 Express editions and provides a solid base to build and deploy applications developed using C/C++, Java, .NET, PHP, and other programming languages. FREE! Go There Now!
| | | | Join this webcast to see how IBM Data Studio Developer and pureQuery can take the pain out of Java data access. uApplications developed using both Java and SQL have become a common requirement. Database connectivity using Java Database Connectivity (JDBC) to create an application is a multi-step tedious process, and tooling that covers both SQL and Java has been unavailable, until now. IBM Data Studio introduces the pureQuery platform: a high-performance, Java data access platform focused on simplifying the tasks of developing, managing, and optimizing database applications and services. FREE! Go There Now!
| | | | Asset Reuse is a key strategy for companies looking to create innovative solutions to solve complex software development problems. Searching for, identifying, updating, using and deploying software assets can be a difficult challenge. Listen to this webcast, to learn about strategies and tools that you can leverage for a successful project, including Rational Asset Manager, Rational Software Architect and WebSphere Service Registry and Repository. FREE! Go There Now!
| | | | Discover how Rational tools and best practices for testing can make your job easier. The new Rational Testing eKits provide you with valuable resources – including demos, webcasts, tutorials, and articles – that help you address your specific testing needs across the software lifecycle. Five new eKits are available covering the topics of Requirements and Test Management, Functional Testing, Performance Testing, Code Quality and Embedded Systems, and SOA and Web Services Testing. FREE! Go There Now!
| | | | Try the latest version of IBM Rational Manual Tester V7.0.1 by downloading a free trial from IBM developerWorks. This manual test authoring and execution tool promotes test step reuse to reduce the impact of software change on testers and business analysts and addresses the needs of teams performing at least a portion of their testing manually. FREE! Go There Now!
| | | | Attend this launch webcast with Scott Hebner, Vice President of IBM Rational Marketing and Strategy, where he will overview Rational’s new offerings and programs to help customers accelerate software innovation on System z. He will discuss how these solutions help organizations extend their core business processes toward modern architectures such as SOA and web technologies to deliver business improvements that stand the test of time. FREE! Go There Now!
| | | | The discipline of assembling and delivering software is maturing beyond standard developer-centric compile/test software builds. The end-to-end software development lifecycle is emerging as the new focus moves “Beyond the Build.” Join this on demand webcast to learn about methods for streamlining software delivery and key capabilities of the IBM Rational Build Forge framework for automating build and release management in environments of any size. FREE! Go There Now!
| | | | All FREE IBM® developerWorks Tools! | |