Sunday, February 28, 2010

Valign doesn’t work in iframe

<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 vertically.
Read More »

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: 1.0\n");
$smtp->datasend("From: $fromuser\n");
$smtp->datasend("To: $touser\n");
$smtp->datasend("Subject: $subject\n\n");
$smtp->datasend("$messagebody");
$smtp->dataend();
$smtp->quit();



Make sure you know your smtp address before using these codes. I found many other similar codes online but none is fully working. These codes are fully tested with no problem. Let me know if find any problem with these codes.



P.S.: Please replace your own variables for $touser, $fromuser, $subject, $messagebody in PERL.
Read More »

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 websites such as Facebook, Google, Youtube, etc.
Read More »

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) {
   this.obj = document.all[name];
   this.style = document.all[name].style;
  }
  else if (document.layers) {
   this.obj = document.layers[name];
   this.style = document.layers[name];
  }
}

function toggle(theForm) {
  obj1 = new getObj('myDiv');
  if (obj1.style.visibility == 'visible') {
    obj1.style.visibility = 'hidden';
    obj1.style.position = 'absolute';
  }
  else {
   obj1.style.visibility = 'visible';
   obj1.style.position = 'relative';
  }
}

There are three parts of this implementation:
1) DIV Layer (to wrap the table)
2) Activation (to trap events to activate the hide/unhide action, for this method make sure the form name is called myform or change accordingly)
3) The Javascript Subroutines to handle the hide/unhide action (I'm showing the toggle version which changes the visibility depending on the current exposure)
Read More »

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 the DBI module for PERL before running these codes. You also need to create a database and obtain the database name, user id and password in order to connect to the database.
Read More »

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.ppd

I just reran the command a few days ago and it is still working!
Read More »

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 too!
Read More »

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 as a trigger to the change of content. You can also set up a timer to change the content periodically.
Read More »