Hi all, Phew long time no compelling public input. Actually I've been too busy doing my thesis which I will talk at a time more ... when finished.
This post has something to do with my thesis and are some javascript methods that I had to build to facilitate data collection and validation (although existing frameworks like JQuery that already do, it's always better to know how we do things before the full abstraction).
The following method gets all HTML elements of a specific type and which complies with standard ID received as a parameter.
getElementsLikeID function (tagName, likeID) {var
elementsLike = [];
var elements = document.getElementsByTagName (tagName);
if (elementos! = null) {
var j = 0;
for (i = 0 ; i \u0026lt;elementos.length; i++
){ if( elementos[i].id!=null && elementos[i].id.indexOf(likeID)> -1) {
elementsLike [j + +] = elements [i];
}}}
elementsLike
return;}
If you run getElementsLikeID ('INPUT', 'porcentajes_') returns an array with all the HTML input ID which contains the word 'porcentajes_'.
Using the method "getElementsLikeID" can do a lot of functions, such as a class for changing the various elements of the page.
cambiaClassPorTag function (tagName, likeID, className) {var elements = getElementsLikeID
(tagName, likeID)
if (elementos! = null) {
for (i = 0; i \u0026lt;elementos.length; i + +) {
elements [i]. className = className;
}}
Finally I leave a few methods used to mark multiple checkboxes that have a common name and a checkbox to mark all that are within a column of a table (by clicking on the column marks all the checkboxes).
1) Mark all the checkbox or descmarcar with common name.
checkBoxLikeNameMarcar function (name) {
checkBoxLikeName (name, true);}
checkBoxLikeNameDesmarcar function (name, flag) {
checkBoxLikeName (name, false);}
checkBoxLikeName function (name, flag) {
var checkboxes = document.getElementsByTagName ('INPUT');
for (i = 0; i \u0026lt;checkBoxes.length; i + +) {
if (checkBoxes.type = 'CHECKBOX' & & checkboxes [i]. name.indexOf (name)> -1) {
if (check & &! CheckBox [i]. Checked)
checkboxes [i]. Click ();
else if (! Make & & checkboxes [i]. Checked)
checkboxes [i]. Click ();
}}}
2) Mark all the checkbox in a column in a table.
* The parameter aLink is a link that goes by or at the top of the column.
checkColumna function (aLink) {var
tdPresionado = aLink. ParentNode;
trTabla var = td.parentNode;
var pos = 0;
for (var i = 0; i \u0026lt;trTabla.cells.length; i + +)
if (tr.cells [i] == tdPresionado)
pos = i +1;
for (var i = 2; i \u0026lt;trTabla.parentNode.rows.length; i + +) {
trTabla.parentNode.rows. [i] cells [pos]. getElementsByTagName ('INPUT') [0 ]. click ();}
Well thats all for now, I hope they serve;)
Greetings PS: Merry Christmas and New Year behind ultra xD.
0 comments:
Post a Comment