Sunday, October 18, 2009

Quick way to 'check/uncheck all checkboxes'

I needed to allow my client to 'check/uncheck' all boxes in a multi-row grid. I found this very convenient code that creates a hyperlink to do simply that; add the link anywhere on the A5W page. Only thing, it checks/unchecks ALL boxes on the page, so it is only useful if you have just ONE group of checkboxes on your page.

<a href="javascript:(function(){%20function%20toggle(box){%20temp=box.onchange;%20box.onchange=null;%20box.checked=!box.checked;%20box.onchange=temp;%20}%20var%20x,k,f,j;%20x=document.forms;%20for%20(k=0;%20k<x.length;%20++k)%20{%20f=x[k];%20for%20(j=0;j<f.length;++j)%20if%20(f[j].type.toLowerCase()%20==%20%22checkbox%22)%20toggle(f[j]);%20}%20})();">Check All</a>

Wednesday, October 14, 2009

How to keep track of session variables in a web app

Almost every web application requires multiple session variables that need to be DIM'd and set to a value. A typical example might be setting "session.clientname" to the logged in user's first and last name, for convenient use when you want to display their name on a web page. Other variables are more important, like the logged-in users personal ID (commonly called the ULINK in Alpha web apps) so you can filter out just their records, and perhaps a Company_ID in a multi-tier application where you need to know their Company affiliation while logged in.

I have a standards set of session variables that go into each web app, ones I use all the time. Those are easy to keep track of, I know them by heart. But every web app also needs a host of session variables that are unique to this application. I devised the following method both to keep track of these unique session variable names and also to make it easier for me to add them as I build the application.

The normal process for adding a session variable is to add some Xbasic code either right where you first need the variable, or in a header type file that is included on ALL web pages. The later method ensures the variable is repopulated every time any page is refreshed. There is a reason you might want this, but I won't go into it right here.

Being data-driven to a fault, I now keep all of these extra session variables in a table, and use Xbasic to extract the information from that table in order to DIM and populate the value. I include a convenient checkbox to indicate if the variable is 'protected' or normal. "Protected session variable" is a term unique to Alpha Five.

Hint: click on the images below to get a larger view. If you cannot read all of the text, click this link to get it in a text file. You can also click on the image to get a larger view.

Here is the table structure:



And here is some representitive data for the table. Note that the 'expression' is normal Xbasic, exactly what you might enter directly on the A5W page to populate your variable. If you check 'Protected' it will automatically insert the text required to make the variable protected. If you include a 'Footer_ID' the current value for this variable will appear in the footer of your web application, which is good for debug purposes while you are testing the application online.


Here is the Xbasic on an A5W page I have named header_setvar.a5w. Note that there is NO HTML on this page, just the requried Xbasic. Note that I use 'evaluate_template()' to extract the information from the table. If I don't include that, the results just appear as normal text in the browser, not fired as Xbasic.

Here is the Xbasic on the individual pages to include this header_setvar.a5w. Typically this would go at the top of every A5W page. In reality, I do not place this header_setvar.a5w on individual pages, I include it another page named header_head.a5w, and that page is included on all other pages. But that is personal preference. Just the line that starts with A5W_Include is imporant here.



Here is the Xbasic that goes in the Footer.A5W page to be able to display the values for each of my session variables while testing the application. In the image below, I included some extra code that shows how I can toggle this 'debug' information off and on while online; that is the initial IF-ENDIF statement. The lines you care about to show the session variables are the two lines starting with dta3.



And here is what the footer actually looks like. It may appear to be nonsense to you, but it tells me exactly what is going on in terms of who is logged in and how that has affected the session variables. This is invaluable data while testing. When I go live, I toggle this debug information off.