Friday, December 19th, 2008
The Javascript function ‘document.getElementById(“<ElementId>”)’ which returns a reference to the first object within a document with the specified id, is certainly in my experience a highly utilised method. But it’s a bit restricting, certainly in a lot of grid work I’ve done over the past few years.
Why should we restrict the locating of specific elements to just the id attribute? Why not any other attribute? If I have a grid of elements, for example text inputs, I might want to organise them into rows and columns.
<input type="text" id="cost" row="4" col="6"/>
Now if I want to reference this control from the entire page of controls by it’s position without knowing it’s id is ‘cost’, there’s no straightforward way of doing so. It feels like this should already be available to us. For example, perhaps the control directly below this (on row 5 col 6) has focus and we wish to be able to press the up cursor key and have the focus change to this control on row 4 col 6. This would be much like using cursor keys to move around a spreadsheet. If we could search for the controls by some other attribute like row and col this would be easy. Don’t get me wrong, this is completely possible using getElementById, you could simply encode the row and column into the id attribute, as I have done many times before.
<input type="text" id="r4c6"/>...
<input type="text" id="r5c6"/>... control with current focus
read more »
Tags: javascript attributes getElementById grid
Posted in Programming |
No Comments »