Page 3 of 4
Some controls are built up using multiple HTML tags and this is one the things that Spartan Ajax can really simplify. We can opt to bundle the various objects together in the wrapper so that the whole control is created in one step.
For example, to create a drop-down list in HTML you have to use a select tag which contains a number of options tags – one for each option in the list. We can wrap the selection control so that all the programmer needs to do to create it is to provide a list of options as an array:
Now we have created the select object we can loop through each of the options specified in the array, create an option object for each one and add it to the select object:
The only complication is that IE doesn’t implement the add method correctly and so we need a try-catch construct to see which form of “add” actually works. With this added to the framework we can create a selection control very simply:
new Array( "Option one",
Creating lists with any number of options is just as easy.
The easy way to create a select list
The table object
Creating the table object is straightforward:
Now all we have to do is create r row objects and add c cell objects to each row. This is just a matter of two for loops. The first creates the row objects:
The second adds the cell objects to each of the rows:
That’s all there is to it!
With this new definition, creating four rows and seven columns is as easy as:
We can also access any cell in the table to use its content with an instruction something like:
However it is also easy to add a method to the table class that returns or sets the contents of the cell:
Now you can set the content of a cell using:
table1.cellvalue (3,2,"More text");
and return the content of a cell using:
You can even write:
which copies the contents of row 2 column 3 to row 1 column 1.
Obviously you can continue to add methods and properties to make using a table much easier. One that is indispensable, however, is a method to return a pointer to a cell object at a given row and column:
Once you have the cell reference you can do anything you want to the cell by getting directly at its properties and methods.
An easy to use table