March 2004 Technical Tip Ė Dynamic TABINDEX with PHP

Do you know what LAMP is? If you donít, you should! At the end of this article I will tell you what LAMP is. Iíll give you a hint: the P stands for PHP, and thatís the subject of this monthís article. PHP is an open source server-side scripting language. PHP is similar to JavaScript in that it is embedded in an HTML file. But whereas JavaScript is processed on the client side, PHP is processed on the server side. Consequently, the client does not see any PHP code: choose View, Source and all youíll see is HTML.

PHP can even be used to access MySQL databases (we talked about MySQL in our January and February articles.) But even if all you know is HTML, you can benefit from some simple PHP knoweldge. Consider the following web page:

The tab key will cause movement through the table from left to right, top to bottom. But what if you wanted to move from top to bottom, left to right instead? You could use the tabindex attribute in the <input> tag to control tabbing, for example:

<td><input type="text" name="r1c1" value="row 1 clm 1" tabindex="11"/>

Maintaining code like this is easy if the table is small, but not so with a large table. It would be nice if the tabindex value could be dynamically generated, and that is just what you can do with PHP. PHP tags begin with <? and end with ?>. The echo command shows the value of its parameters, that value therefore being included in the final HTML code. The above could be changed as follows:

<td><input type="text" name="r1c1" value="row 1 clm 1" tabindex="<? echo ($tab++)."1"; ?>"/>

Thereís a little more to it than this, so be sure to check out the complete source at (Note: I have used a .txt extension instead of .php or you might not be able to view it!)

Now to answer the question posed at the beginning of this article: LAMP stands for Linus + Apache + MySQL + PHP, all of which are open source. We hope you will consider Caliber Data Training for all your training needs: let us shed some light on LAMP!

Go to the articles index. Written by Bill Qualls. Copyright © 2004 by Caliber Data Training 800.938.1222