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 probably have thousands of lines of COBOL code loaded with business intelligence and being used to run your business, along with an army of developers maintaining these applications. Learn how to prepare your applications and developers so you can keep that competitive edge and move to a service-oriented architecture with the IBM Rational Enterprise Modernization solutions. Replay is available for 9 months. FREE! Go There Now!
| | | | Poor Requirements Management capabilities in an Enterprise have been linked to excessive project failures, escalating IT costs, and failure to deliver competitive advantage into the marketplace. Join Brianna M Smith from IBM Rational and learn about how successful organizations align IT and Business stakeholders through collaborative processes and tools for effective requirements management, and how an integrated approach across the IT lifecycle can provide unparalleled visibility and traceability to ensure that project teams are delivering on the business vision by "doing the right things" and "doing things right." FREE! Go There Now!
| | | | Learn how you can extend modern application lifecycle management to IBM System z through the IBM Rational Software Delivery Platform (SDP). The Did you say mainframe? e-kit includes podcasts, webcasts, tutorials, white and red papers, demos, and articles designed to help ease the challenges of modernizing your enterprise. This complimentary kit for mainframe developers is a practical, how-to guide for making the most of an existing development environment, including the skills and infrastructure already in place at an established enterprise. FREE! Go There Now!
| | | | This webcast outlines the best practices that must be instituted to gain the maximum benefit from SOA while maintaining high quality of service. Whether you are deploying new applications or managing and monitoring your existing infrastructure, learn how you can ensure high quality of services with SOA based solutions from IBM. All registrants who attend this live Web Seminar will receive complimentary access to a white paper titled “Maintaining QoS in an SOA Environment”. FREE! Go There Now!
| | | | Join this Rational Talks to You teleconference on December 11 at 1:00 pm ET to get tips on building your own plugins with Rational Method Composer. Get your questions answered! FREE! Go There Now!
| | | | Join this Rational Talks to You teleconference on November 29 at 1:00 pm ET to participate in an interactive discusssion with Grady Booch around architecture and reuse. Get your questions answered! FREE! Go There Now!
| | | | This whitepaper provides areas to consider when evaluating any software configuration management solution. It addresses how the IBM solutions (Rational ClearCase and Rational ClearQuest) meet the needs and requirements of both project leaders and developers to provide successful Software Change and Configuration Management. FREE! Go There Now!
| | | | Get a free trial download of the latest version of IBM Rational Performance Tester V7.0.1, a load and performance testing solution for teams concerned about the scalability of their Web-based applications. Combining multiple ease-of-use features with granular detail, Rational Performance Tester simplifies the test-creation, load-generation and data-collection processes that help teams ensure the ability of their applications to accommodate required user loads. FREE! Go There Now!
| | | | Whether you are creating new applications or modifying existing ones, managing integration of new components with traditional z/OS elements is a critical part of building and deploying modern applications. Listen to this webcast to see how IBM can help you optimize your development process using an IDE like Rational Developer for System z that integrates with management tools, such as ClearCase to manage your application development on mainframes. FREE! Go There Now!
| | | | Explore how Rational and WebSphere software enable enterprise documentation in SOA environments. Specifically, a new integration between IBM WebSphere® Business Modeler and IBM Rational® Method Composer software can help technical writers more easily keep enterprise operations manuals in sync with changes that are made to business processes, resulting in more accurate and timely documentation that benefits the entire enterprise. FREE! Go There Now!
| | | | All FREE IBM® developerWorks Tools! | |