<iframe> vertical alignment doesn’t work with normal valign property declaration. It has to be adjusted using CSS. Here’s the CSS codes:iframe { vertical-alignment: top; }By default if this is set, it aligned to the middle vertical...
Sunday, February 28, 2010
Saturday, February 27, 2010
Sending Email using PERL Net::SMTP module
I recently bumped into a problem with my old CGI script that sends emails from LINUX/UNIX server in PERL platform.I later found out that the server I rented/shared is no longer supporting emails using the sendmail –t command. I found a solution to it by using the PERL module of Net::SMTP.Here are the codes that saved my day:use Net::SMTP; $smtp = Net::SMTP->new("smtp.yourdomain.com"); $smtp->mail("username\@ yourdomain.com"); $smtp->to($touser); $smtp->data(); $smtp->datasend("MIME-Version:...
Friday, February 26, 2010
My Lazy Confession
I like to use shortkey, especially the address bar shortcut.I like to use CTRL-ENTER whenever I type the web address.For example in the address bar,I type yahoo followed by CTRL-ENTER. The browser will complete it as http://www.yahoo.com and go to this address. Whether it is IE, Safari, Firefox or Chrome, it is able to perform this trick.Lazy me, lazy me...
Update (April 5th, 2016): Most browsers can now "auto-complete" your website address if you type in the domain name of popular...
Thursday, February 25, 2010
Javascript to hide/unhide table layer for IE+Firefox+Safari
HTML (Div Layer):<div id="myDiv" style="position:absolute; visibility:hidden; width=100%;"><table ......</table></div>HTML (Event Starter):<input type=checkbox name=mycheckboxid onclick="javascript:toggle(document.myform);">Javascript:function getObj(name){ if (document.getElementById) { this.obj = document.getElementById(name); this.style = document.getElementById(name).style; } else if (document.all)...
Wednesday, February 24, 2010
PERL connect to DBI subroutines (smart detect)
Here are the codes:sub connect_db { if (!$connect) { $dbh = DBI->connect("dbi:mysql:your_db_name;host=localhost:3306;user=db_user;password=user_password") or die "Couldn't connect to database: DBI::errstr\n"; $connect = 1; }}sub disconnect_db { $dbh->disconnect; $connect = 0;}Try to use as little disconnect as possible as connecting and disconnecting may cause delay and to the HTML connection. As you may already know you may need to install...
Tuesday, February 23, 2010
Installing PERL CRYPT:SSLEAY module
This module is important for SSL - LWP connections. I used this command to install the module using ppm (usually in c:\Perl\bin):ppm> install http://theoryx5.uwinnipeg.ca/ppms/Crypt-SSLeay.ppdI just reran the command a few days ago and it is still worki...
Monday, February 22, 2010
How do you scroll to the top within iframe?
I have tried:parent.scroll(0,0);window.scroll(0,0);...Finally I found a site that says:window.parent.scroll(0,0);That saved my day! Hope it works for you t...
Sunday, February 21, 2010
How to dynamically display the content of your Cookie using Javascript?
Almost the same as the previous post. Just need to replace the cookie variable in the assignment of innerHTML.HTML:<span id="myHTML"></span>Javacript:document.getElementById('myHTML').innerHTML = document.cookie.indexOf("myCookieName"); // where 'myCookieName' is the name of the cookie such as the shopping cart item quantity, etc..You can set up a Javascript function to handle this dynamic capability and receive event calls from omouseover, onload, ... HTML event...
Saturday, February 20, 2010
How to dynamically change the content of your HTML using Javascript?
HTML:<span id="myHTML"></span>Javascript:document.getElementById('myHTML').innerHTML = htm; // where 'htm' is a variable to hold the HTML codes you want to display in the <span> portion.You can set up a Javascript function to handle this dynamic capability and receive event calls from omouseover, onload, ... HTML event as a trigger to the change of content. You can also set up a timer to change the content periodical...
Friday, February 19, 2010
Which Broswer is the Best?

It depends on whether you want to use it to surf or you want use it to develop websites.For web developers, it is always Firefox as it comes with tools to help troubleshoot websites and the plug-ins are widely available such as plug-ins to view raw HTTP headers, etc.If you want to use it to surf net, I would recommend Safari and Chrome. I use to like Safari. After installing Chrome, Google has the...
Thursday, February 18, 2010
Who says CGI/PERL is obsolete?
Some say CGI/PERL is slow.Some say CGI/PERL has security problem.Some say CGI/PERL is phased out by PHP....But there is still one "BIG" website that is still using CGI/PERL until today. Have you seen this:https://www.paypal.com/my/cgi-bin/webscrIf CGI/PERL is not good, why is PayPal still using it until today to deal with large sum of credit everyday?
UPDATE (April 4th, 2016): It has been six years since I posted this comment about PERL's popularity. But I now would say PERL is already...
Wednesday, February 17, 2010
Google Chrome Review

I have decided to add Google Chrome browser to my browser list as test vehicle of websites I built or am going to build.The download path is http://www.google.com/chrome/After clicking the download button, a terms-and-conditions page appeared asking downloader to "agree and download".The download file is called ChromeSetup.exe and it is just 551KB. Very small. It takes around a second to download...
Tuesday, February 16, 2010
Speeding Up PERL in CGI Output
Usually I will do the following setting:select(STDOUT);$| = 1;print "Content-type: text/html\n\n"; # whenever your browser sees this, it will blank the screen$| = 0;$| = 1; is to make sure to send data to client web browser immediately. It is like a "live" connection.$| = 0; is to make sure to send data to client web browser only when the buffer is filled.Such configuration can make the user feel that the response of the web is fast but it is actually just slightly faster.If you use...
Monday, February 15, 2010
PERL Trick to Make Alternative Row Color
The mod or modular operator in PERL (%) is responsible for this trick.The following codes show how I did it:... $total_hits++; if ($total_hits % 2) { $rowcolor = " bgcolor=#FFEEEE"; } else { $rowcolor = " bgcolor=#FFFFFF"; }...These codes are in a loop to list out all the items. You can place the $rowcolor in the <TR> tag. The rows displayed will be in pink and white alternative...
Sunday, February 14, 2010
The Maximum Length of a Cookie Name
I once encountered a problem with the cookie length with Firefox when the cookie name or value is too long.I now try to imitate the same problem I encountered last time, the problem is gone.But I use shorter cookie name and value so that Firefox won't reject them I encountered last time which caused me a lots of pain debugging.It's good to test cookies using firefox as one can view the cookies easily using this:Tools->Options...->Privacy->Show CookiesThank goodness there is a...
Saturday, February 13, 2010
PERL codes to check whether a image file Exists
Here are the codes I have been using. The key is to use the "-e" in the if statement. Other than that it is not a hard programming problem: if (-e "../htdocs/prod/small/$image_id.jpg") { $img_path = "/prod/small/$image_id.jpg"; } else { $img_path = "/img/default_small.gif"; }Those in red (the relative path to the cgi-bin directory) depend on your server's configuration. One needs to ftp into the server to see the structure.You can also "elsif" to support more file format rather than...
Friday, February 12, 2010
The FTP software I like best

I like Filezilla. Especially the "File permissions..." feature, one can easily set the file permission without having to worry much about. You can even set permission for many files at the same time. Anyway, this only applies to Linux/Unix based servers. For Windows based servers, the file permission has to be set in the control panel.I have used many other FTP softwares before. Nothing compares to...
Thursday, February 11, 2010
How to highlight the entire <TR> during mouseover?
For IE, this doctype or similar one is needed:<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01//EN" "http://www.w3.org/TR/html4/strict.dtd">If you use onmouseover+onmouseout to change the style using the method I mentioned before could be painful.I came across a method which is code saving:- use TR:hover.First I have this CSS declared:tr.rowname:hover { background-color: #FF8888; color: #FFF; }And I used it in HTML:<tr bgcolor=#FFF1F1 class=rowname><td>blah blah blah</td></tr>This...
Wednesday, February 10, 2010
IE Bug#1
If you have a DIV and you don't specify the width, the DIV won't show up ever until you specify the width.I have tried the same thing on Firefox and Safari, they are both able to show the DIV without having to specify the width of the D...
Tuesday, February 9, 2010
Randomize Image Display using PERL
From HTML side:<img src="/cgi-bin/myimage">From PERL side (myimage):#!/usr/local/bin/perlprint "Content-type: image/gif\n\n";$pic[0] = "image0.gif";$pic[1] = "image1.gif";$pic[2] = "image2.gif";$rndm = int(rand()*3);open(PIC, "./../image/$pic[$rndm]");binmode(PIC);binmode(STDOUT);while (<PIC>) { print $_;}close(PIC);This is neat. Seldom a programmer reveals this simple but neat secr...
Monday, February 8, 2010
Randomize Image Display using Javascript
When you reach the location of your HTML that you need to display an randomized image, you can use these codes as a reference:<script language="javascript"><!--var rn = "";rn = Math.floor(Math.random()*11);if (rn == "0") {document.write("<img src=\"/img/pic0.jpg\">");}if (rn == "1") {document.write("<img src=\"/img/pic1.jpg\">");}if (rn == "2") {document.write("<img src=\"/img/pic2.jpg\">");}if (rn == "3") {document.write("<img src=\"/img/pic3.jpg\">");}if...
Sunday, February 7, 2010
Set Cookie with Variable Using Eval in Javascript
Have you ever encountered a situation that you need to set a cookie with a javascript variable added to a cookie? But you cannot use "+" in your cookie assignment?Here is where the javascript eval() comes into play:function assignfruit(type) { eval('document.cookie = "fruit='+ type +';"');}Since you cannot do this: document.cookie = "fruit="+ type +";" or this: document.cookie = 'fruit='+ type +';', you need to use eval().Something I found out and I think it is useful to beginners to...
Saturday, February 6, 2010
How to process Selection/Radio/Checkbox data using Javascript?
This corresponds with the previous post:For Pull-Down Selection:document.docname.variablename.selectedIndex// Replace docname with your document name and variablename with your selection variable name such as country. The selectedIndex starts from 0 which is the first item in your pull down selection list.For Radio Selection:document.docname.variablename[index].checked// If selected, this notation will become 1. The index starts from 0. If your radio selections have two items, the first...
Friday, February 5, 2010
How to process Selection/Radio/Checkbox data in PERL?
This corresponds with the previous post:For Pull-Down Selection:if ($form_data{'country'} eq "Australia") {...}For Radio Selection:if ($form_data{'type'} eq "orange") {...}For Checkbox Selection:if ($form_data{'type'} eq "on") {...}Please check with the previous posts for the the input/selection HTML. Please also note that you need to have the legendary cgi-lib.pl library called before you can use $form_data{'---'} hash table that captures the query strings from your HTML document.P.S.:...
Thursday, February 4, 2010
All the Pre-selections and Pre-checks in HTML Selection ie. OPTION and INPUT(Radio+Checkbox)
For Pull-Down Selection:<select name=country><option>Argentina</option><option selected>Australia</option><option>Austria</option><option>Bahamas</option>...</select>For Radio Selection:Orange <input type=radio name=type value=apple checked> Apple <input type=radio name=type value=orange>For Checkbox Selection:<input type=checkbox name=type checked>Coming next, how to detect those selections in PERL-CGI scri...
Wednesday, February 3, 2010
Weird Image Alignment Problem in HTML

Ever encounter this problem?The alignment of your image and the adjacent text seem hard to be aligned. The text is always lower than the lowest part of the image. No matter how you adjust the CSS of the <img>, nothing works.There is a simple solution to this:<Table><TR><TD><img src="/image/but1.gif"></TD><TD><a href="[http_address]">Click if you need...
Tuesday, February 2, 2010
How to fix HTML table problem?
This is the most common problem that a web developer faces throughout his or her career. It is the table problem. Why is the text not aligned? Why is the image glued to the other end instead being centered? These are the common questions in mind especially when you have many layers of tables stacked up to each other.There is a easy fix to this. COLOR IT!But RULE#1 before this. Make a backup copy. When you have a copy backed up, you dare to do any experiment with it. Usually I will purposely...
Monday, February 1, 2010
How to perform double underline in HTML?
It is just a trick I learned recently to double underline the grand total in a shopping cart.Actually there is no direct solution to this.The trick is to combine both conventional <u> and CSS to perform the trick.Here are the codes:<table><tr><td style="border-bottom: 1px double #000;"><u>underline this</u><td><tr></table>Yes, the double needs to be there and so is <u>. Make sure your <td> is as narrow as possible or the...
Subscribe to:
Posts (Atom)