HPMJe Programming Blog

Learn more...do more. It's that simple!

Subscribe to RSS feed

JavaScript Table Sorting Script

, , , ...

Ever wanted to create a script that will allow you to dynamically sort table rows by column in alphabetic an numeric order? You don't have to code this. It's available for you to use. I have created a package for you with the necessary files : Table Sorting Script.zip Now...you'll need to create (or use an existent) HTML file and include a reference to both the JavaScript the CSS file. Then you'll need a TABLE with a THEAD and TBODY. Something like this :
<table>
    <thead>
        <tr>
            <td>Title</td>
            <td>Description</td>
        </tr>
    </thead>
    <tbody>
        <tr>
            <td>Title 01</td>
            <td>Description 01...</td>
        </tr>
        <tr>
            <td>Title 02</td>
            <td>Description 02...</td>
        </tr>
    </tbody>
</table>

<style type="text/css">
@import url('tablesort.css');
</style>

<script type="text/javascript" src="tablesort.js"></script>
Give it a try! It really works great! Remember, you can change the styles in the "tablesort.css" file. ! Please note. I didn't not write this code. The website of the original author is : http://www.tagarga.com/blok/post/2

JavaScript Alert Message

, , , ...

This is a very simple tutorial.
Even so, many people not knowing how to do this will find it useful.

Ok...ever wanted to create an alert message using JavaScript which is triggered upon clicking a link/button/image/etc... ? Its very easy and you can read further to find out how.

First you'll need some code to trigger your JavaScript alert message.

Button Example :
<input type="button" name="alertMessage" value="Alert Message" onclick="alert('This is an alert message!');" />


Hyperlink Example :
<a href="javascript:alert('This is an alert message!');" title="Alert Message">Alert Message</a>


Now...that was relatively simple, wasn't it?
You can expand the functionality and create a function with an array of messages.

Alert Messages Function Example :
function alertMessage(mess)
{
    var alertMessages = new Array();
    alertMessages['firstMessage'] = "This is my first alert message";
    alertMessages['secondMessage'] = "This is my second alert message";

    alert(alertMessages[mess]);
}


...and you can trigger this function by using something like this :

<input type="button" name="firstMessage" value="First Message" onclick="alertMessage('firstMessage');" />


Great! I hope that you learnt something.
Please feel free to post your comments and ideas.

Apache URL Rewriting

, , , ...

Ever wanted to create those perfectly pretty search engine friendly URLs displaying the way you want them to without them actually being what they seem to be? Sounds confusing, but it truly is deliciously interesting and fun. Not only that, but these SEO frienly URLs are both extremely useful and powerful when it comes to search engines and usability.

Let me give you a quick introduction which will explain to you better how this works and why you would want to use something like this.

Possible Reasons for Usage :

  1. Search Engine Optimization
  2. Usability In General
  3. File Protection (YES)


Let's say that you have a dynamic website, developed in PHP, MySQL and other related languages. You have a set of PHP files (possibly objects or object calling functions) which are retrieving information/data from your MySQL database using built in PHP functions. This is just the general idea. With something remotely similar to what I just said, you might end up with URLs like these :

http://www.domain.com/filename.php?method=viewArticle&articleId=32&type=html

Yup, it's a normal, dynamic URL. We see them all over the web. Even so, we all have the ability to improve our sites by literally converting these terribly confusing and complex looking URLs into something more pleasant and appealing like this :

http://www.domain.com/articles/myCategoryTitle-3/myArticleTitle-32.html

Off course, the latter URL is just a quick sample of what you are capable of doing. It will obviously require a little bit more work (programming) to achieve this, but it truly is possible.

Where the hell did that ".html" come from? Exactly...its confusing, since the ".html" file isn't actually created, and doesn't really exist at all. You'll see how it works just now.

To achieve something like I just did above, you'll have a ".htaccess" file with the following code in it :

Options +FollowSymLinks
RewriteEngine on
RewriteRule articles/(.*)-(.*)/(.*)-(.*).(.*) articles.php?method=viewArticle&categoryId=$2&articleId=$4&type=$5


Yup...it's as simple as that.
May 2012
S M T W T F S
April 2012June 2012
1 2 3 4 5
6 7 8 9 10 11 12
13 14 15 16 17 18 19
20 21 22 23 24 25 26
27 28 29 30 31