02
Sat, Nov
2 New Articles

TechTip: Spice Up Your Web Pages

Web Languages
Typography
  • Smaller Small Medium Big Bigger
  • Default Helvetica Segoe Georgia Times

I like programming CGI and HTML, partly because of the wealth of clever programming examples you can find. You do not have to be a JavaScript or CSS wizard to incorporate advanced stuff on your own pages. Many clever programmers have already invented almost everything you can think of, and the best thing is that they're willing to share most of it for free! That is, in my opinion, a great approach to learning something new.

(Note: If you have absolutely no experience at all in JavaScript, look at this article written by Joe Pluta: "JavaScript: What, Why, and How.")

In this TechTip, I will "spice up" some pretty dull Web pages with an RPG CGI program. You do not have to understand every JavaScript or CSS statement or keyword that I use (I don't either), because it does not really matter as long as you get it to work and have an idea of how it functions.

So please read on to take a little trip into the amazing world of JavaScript and CSS.

Figure 1 shows a browser window.

http://www.mcpressonline.com/articles/images/2002/spiceV4--11030600.jpg

Figure 1: This is a sample browser window. (Click images to enlarge.)

The Web page is built from what you in HTML call "frames." If you are unfamiliar with frames, they are best described as different windows on a Web page in which different HTML pages can be shown. In order to give you an idea, I am showing the frames and their names in red in the figure. I also show the name of the input fields and buttons. The names of the HTML documents displayed in the various frames are listed in blue.

The Web browser sees every frame on the page as an object, and in order for the browser to refer to the object, it has to have a name. The browser also sees every input field and every button on the page as an object, and they also have names. So let's says you are located in the main frame and want to insert text in the top frame in the title field. The JavaScript syntax will be something like this:

parent.topframe.document.DataForm.title.value = 'some text';

Or you could use the ID attribute included in the Document Object Model (DOM):

parent.topframe.document.getElementById('title').value = 'some text';

Either will work just fine.

Now, let's get on with a working example.

Installing

To start, you need to first install the HTML documents and the RPG CGI program:

  1. Create a folder on your i5 Web server called your-www-folder/mcpressonline/spice.
  2. Download spice.zip and unzip and FTP/copy everything to the /mcpressonline/spice folder. (Note that the zip file contains only four HTML documents; more will follow in my next tip.)
  3. Download RPG CGI source member FORM008 and place it in your CGI library.
  4. Download HTML skeleton member FORM008H and place it in your CGI library.
  5. Download savefile ALBUMS.savf, FTP it to your Web server, and restore it into your CGI data library or somewhere else.
  6. If you do not have a version of CGIPARSEZ, download it here. Follow the instructions in the header to compile.

You're now almost done, but you have to change a few things before you compile the source files.

In FORM008, change keyword ExtFile "your-data-lib" on the F-spec for ALBUMS to where you placed the ALBUMS database. also In FORM008, change keyword ExtFile "your-CGI-lib/your-CGI-file" on the F-spec for QRPGSRC to where you placed the FORM0008H member. In my case, the keywords look like this:

ExtFile( 'CGIDATA/ALBUMS' )
ExtMbr( '*FIRST' )        

ExtFile( 'CGILIB/QRPGSRC' )
ExtMbr( 'FORM008H' )       
UsrOpn                      

Now, open HTML document top.htm and find the . Change "your-web-server" to the name/IP of your Web server:

That's it. Let's continue to see what can be done.

Figure 2 shows the old, dull Web page. The data content is OK; it's a listing of some of the Elvis Costello albums in my record collection. It could of course have been a customer database or a product database, but along with this TechTip, I thought I would give you a little culture as well.

http://www.mcpressonline.com/articles/images/2002/spiceV4--11030601.jpg

Figure 2: Jan keeps a database of his Elvis Costello albums.

Now, let's spice up this page:

  1. Position your cursor in the title field.
  2. Change the background color when the cursor is inside an input field.
  3. Write a status message when the page is loading, and write a new one when the page is done loading.
  4. Change the background color on the table rows to color1/color2.
  5. Change the background color on a table row when the mouse hovers over it.

When you're done, the page will look like this:

http://www.mcpressonline.com/articles/images/2002/spiceV4--11030602.jpg

Figure 3: You've added some spice to your page!

If you have read my recent TechTips, you know that I normally build a Web page from various different blocks. The same applies to this tip. The page is built of some HTML documents, an RPG CGI program, and an HTML source skeleton member, which is read by the RPG CGI program. Certain values will be replaced on the way.

The difficult part in all this is to keep track of the different blocks. If you use IE, the easiest way is to place your cursor on the part of the Web site you want to know something about, right-click, and select Properties. Then you can see the name of the HTML document or the RPG CGI program. If you use Firefox, you can download plug-ins that analyze Web pages in a much more advanced way than IE can, but for now, we'll just stick to the simple stuff.

Below, I show how the various steps are done. I encourage you to try changing some of the scripts and see the new result.

1. Position cursor (see HTML file top.htm).

Place a function call on the tag and then call it using the onLoad event when the page loads:

 calls function SetFocus 

function SetFocus() {
document.getElementById('title').select();
document.getElementById('title').focus();
}

Here, I use the select() and focus() built-in functions and run them against the title field.

2. Change background color when cursor is inside an input field (see HTML file top.htm).

On the input tags, I use the onfocus and onblur events and some CSS to change the background colour:

onfocus="this.style.background = '#e7e7e7'" (makes the color light grey)
onblur="this.style.background = '#ffffff'" (makes the color white)

Note: If you want a red background with blue text, just change the onfocus to onfocus="this.style.background = '#FF0000',this.style.color = '#000080'"

3. Write a status message while the page is loading (see HTML files top.htm and msg.htm).

In Figure 1, you'll see a frame called msg. That's where the various messages should appear.

In message.htm, I have defined an input field, added some CSS to remove the border, and so on. But I have also embedded it inside a

tag and given it CSS style "hidden," which of course hides the content of the input tag.

In top.htm, I call the SendMsg function, which makes the input fields visible and then writes a message in the field. This is done using the onClick event, which is placed on the Search button. To access objects in different frames, use the parent built-in function:

function SendMsg() {
parent.msgframe.document.getElementById("textbox").style.display='block';
parent.msgframe.document.getElementById("message").value =  'Loading data, please wait...';
}  

After the Search button is clicked, RPG CGI program FORM008 is called; it reads the input (if any) from the form, processes it, reads the ALBUMS data file, builds the list of data, and sends it back to the browser. It also writes out a completion message that indicates that the page is loaded and identifies how many entries where found.

If you search for %%complete%% in FORM008H, you'll see that I have added some JavaScript to the HTML document, but it is not part of a function. When you do this, the JavaScript will be executed when the browser reaches the lines where the code is. In this case, I just replaced the %%complete%% keyword with the number of entries found, and the program writes the result to the browser in msgframe, using the same syntax as before.
Finally, it positions the cursor in the title field and marks the field content.

                            
                                                    
                                                 

One important thing about this trick, which is called "cross-framing," is that all the documents must reside on the same Web server; otherwise, you will get an "access denied" message. Even though it seems a little odd, it is really good that it cannot be done if you think about it.

(If you are interested in cross-framing between different servers, let me know and I might write a TechTip about that as well.)

4. Change the background color on the table rows to color1/color2 (see RPG CGI program FROM008 and search for SwapColor).

This is done by adding the bgcolor attribute to the tag. Then, in the RPG CGI program, I use field SwapColor to pass set RowBgColor to either constant BgColor1 (#b7cae3) or constant BgColor2 (#e7e7e7).

5. Change the background color on a table row when the mouse hovers over it (see RPG CGI program FORM008, search for onMouseOver, and look in FORM008H after function TG).

This is done by calling function TG, which is in the tag with the onMouseOver and onMouseOut events. If you want this to happen on the data cell level, move the function call to the tag.

The function looks like this:

function TG(a, changeTo)             
{                                    
a.style.backgroundColor = changeTo;  
}                                    

Then, in the RPG CGI program, I use field SwapColor to pass either constant BgColor1 or constant BgColor2 to the function. The deed is done!

Compiling and Running the Example

CRTRPGMOD MODULE(yourlib/FORM008) SRCFILE(yourlib/QRPGSRC)
SRCMBR(FORM008) DBGVIEW(*SOURCE) REPLACE(*YES)            


CRTPGM PGM(yourlib/FORM008) MODULE(FORM008)
BNDSRVPGM(QHTTPSVR/QZHBCGI)                

http://your-web-server/mcpressonline/spice/index.htm

It's Easy!

I hope this tip has shown you that it is not difficult to improve the Web interface if you know just a little bit of JavaScript and CSS.

This completes part one of this TechTip. In my next TechTip, I will add a feature to the program that will show an image of the cover in the coverframe. In the meantime, keep searching the Web to find clever JavaScript and CSS stuff.

Jan Jorgensen is a programmer at Electrolux Laundry Systems Denmark. He works with stuff like RPG, HTML, JavaScript, and Perl. You can reach him at This email address is being protected from spambots. You need JavaScript enabled to view it..

Jan Jorgensen

Jan Jorgensen is one of the owners of www.reeft.dk, which specializes in mobile and i5 solutions. He works with RPG, HTML, JavaScript, Perl, and PHP. You can reach him at This email address is being protected from spambots. You need JavaScript enabled to view it.

 

BLOG COMMENTS POWERED BY DISQUS

LATEST COMMENTS

Support MC Press Online

$

Book Reviews

Resource Center

  • SB Profound WC 5536 Have you been wondering about Node.js? Our free Node.js Webinar Series takes you from total beginner to creating a fully-functional IBM i Node.js business application. You can find Part 1 here. In Part 2 of our free Node.js Webinar Series, Brian May teaches you the different tooling options available for writing code, debugging, and using Git for version control. Brian will briefly discuss the different tools available, and demonstrate his preferred setup for Node development on IBM i or any platform. Attend this webinar to learn:

  • SB Profound WP 5539More than ever, there is a demand for IT to deliver innovation. Your IBM i has been an essential part of your business operations for years. However, your organization may struggle to maintain the current system and implement new projects. The thousands of customers we've worked with and surveyed state that expectations regarding the digital footprint and vision of the company are not aligned with the current IT environment.

  • SB HelpSystems ROBOT Generic IBM announced the E1080 servers using the latest Power10 processor in September 2021. The most powerful processor from IBM to date, Power10 is designed to handle the demands of doing business in today’s high-tech atmosphere, including running cloud applications, supporting big data, and managing AI workloads. But what does Power10 mean for your data center? In this recorded webinar, IBMers Dan Sundt and Dylan Boday join IBM Power Champion Tom Huntington for a discussion on why Power10 technology is the right strategic investment if you run IBM i, AIX, or Linux. In this action-packed hour, Tom will share trends from the IBM i and AIX user communities while Dan and Dylan dive into the tech specs for key hardware, including:

  • Magic MarkTRY the one package that solves all your document design and printing challenges on all your platforms. Produce bar code labels, electronic forms, ad hoc reports, and RFID tags – without programming! MarkMagic is the only document design and print solution that combines report writing, WYSIWYG label and forms design, and conditional printing in one integrated product. Make sure your data survives when catastrophe hits. Request your trial now!  Request Now.

  • SB HelpSystems ROBOT GenericForms of ransomware has been around for over 30 years, and with more and more organizations suffering attacks each year, it continues to endure. What has made ransomware such a durable threat and what is the best way to combat it? In order to prevent ransomware, organizations must first understand how it works.

  • SB HelpSystems ROBOT GenericIT security is a top priority for businesses around the world, but most IBM i pros don’t know where to begin—and most cybersecurity experts don’t know IBM i. In this session, Robin Tatam explores the business impact of lax IBM i security, the top vulnerabilities putting IBM i at risk, and the steps you can take to protect your organization. If you’re looking to avoid unexpected downtime or corrupted data, you don’t want to miss this session.

  • SB HelpSystems ROBOT GenericCan you trust all of your users all of the time? A typical end user receives 16 malicious emails each month, but only 17 percent of these phishing campaigns are reported to IT. Once an attack is underway, most organizations won’t discover the breach until six months later. A staggering amount of damage can occur in that time. Despite these risks, 93 percent of organizations are leaving their IBM i systems vulnerable to cybercrime. In this on-demand webinar, IBM i security experts Robin Tatam and Sandi Moore will reveal:

  • FORTRA Disaster protection is vital to every business. Yet, it often consists of patched together procedures that are prone to error. From automatic backups to data encryption to media management, Robot automates the routine (yet often complex) tasks of iSeries backup and recovery, saving you time and money and making the process safer and more reliable. Automate your backups with the Robot Backup and Recovery Solution. Key features include:

  • FORTRAManaging messages on your IBM i can be more than a full-time job if you have to do it manually. Messages need a response and resources must be monitored—often over multiple systems and across platforms. How can you be sure you won’t miss important system events? Automate your message center with the Robot Message Management Solution. Key features include:

  • FORTRAThe thought of printing, distributing, and storing iSeries reports manually may reduce you to tears. Paper and labor costs associated with report generation can spiral out of control. Mountains of paper threaten to swamp your files. Robot automates report bursting, distribution, bundling, and archiving, and offers secure, selective online report viewing. Manage your reports with the Robot Report Management Solution. Key features include:

  • FORTRAFor over 30 years, Robot has been a leader in systems management for IBM i. With batch job creation and scheduling at its core, the Robot Job Scheduling Solution reduces the opportunity for human error and helps you maintain service levels, automating even the biggest, most complex runbooks. Manage your job schedule with the Robot Job Scheduling Solution. Key features include:

  • LANSA Business users want new applications now. Market and regulatory pressures require faster application updates and delivery into production. Your IBM i developers may be approaching retirement, and you see no sure way to fill their positions with experienced developers. In addition, you may be caught between maintaining your existing applications and the uncertainty of moving to something new.

  • LANSAWhen it comes to creating your business applications, there are hundreds of coding platforms and programming languages to choose from. These options range from very complex traditional programming languages to Low-Code platforms where sometimes no traditional coding experience is needed. Download our whitepaper, The Power of Writing Code in a Low-Code Solution, and:

  • LANSASupply Chain is becoming increasingly complex and unpredictable. From raw materials for manufacturing to food supply chains, the journey from source to production to delivery to consumers is marred with inefficiencies, manual processes, shortages, recalls, counterfeits, and scandals. In this webinar, we discuss how:

  • The MC Resource Centers bring you the widest selection of white papers, trial software, and on-demand webcasts for you to choose from. >> Review the list of White Papers, Trial Software or On-Demand Webcast at the MC Press Resource Center. >> Add the items to yru Cart and complet he checkout process and submit

  • Profound Logic Have you been wondering about Node.js? Our free Node.js Webinar Series takes you from total beginner to creating a fully-functional IBM i Node.js business application.

  • SB Profound WC 5536Join us for this hour-long webcast that will explore:

  • Fortra IT managers hoping to find new IBM i talent are discovering that the pool of experienced RPG programmers and operators or administrators with intimate knowledge of the operating system and the applications that run on it is small. This begs the question: How will you manage the platform that supports such a big part of your business? This guide offers strategies and software suggestions to help you plan IT staffing and resources and smooth the transition after your AS/400 talent retires. Read on to learn: