...

View Full Version : innerHTML Javascript Function



kapone_pt
05-06-2006, 02:18 PM
Hi All,


Can anyone explain-me waht this javascript function can do:



$ext = new Array();
function regxstuff($tname)
{
$l = 0;
$re = new RegExp('\\".+\\.(\\w+)\\"');
$rar = new RegExp('r[0-9][0-9]');
$par = new RegExp('p[0-9][0-9]');
$ace = new RegExp('c[0-9][0-9]');
$zip = new RegExp('z[0-9][0-9]');

$t = document.getElementById($tname);
for ($i=0; $i < $t.rows.length; $i++)
{
$ex = $re.exec($t.rows[$i].cells[2].innerHTML);

if ($ex)
{
$e = $ex[1].toLowerCase();

if ( !isNaN(parseInt($e)) )
continue;
else if ($e.match($rar))
$e = 'rar';
else if ($e.match($par))
$e = 'par';
else if ($e.match($ace))
$e = 'ace';
else if ($e.match($zip))
$e = 'zip';

if (!$ext[$e])
{
$ext[$e] = new Array(); $l++;
}

$ext[$e].push($i);
}
}

if ($l > 0 && $l < 10)
{
$ext.sort();
$h = "Inverse by type: ";
for (var xyz in $ext)
{
$h += "<input type=\"button\" onClick=\"invtype('"+xyz+"')\" value=\""+xyz+"\" class=\"b\"> ";
}
$h += "<p>";
document.getElementById('invbyt').innerHTML = $h;
}
}

mensa_dropout
05-07-2006, 05:11 PM
it's not all javascript...

looks like it's looping through each cell in a table, trying to match the cell's contents with one of the regular expressions defined at the top of the routine. if a match is found, a corresponding string value ('rar' or 'par' or 'ace' or 'zip') is inserted into an array. after looping through all the cells, the array's contents are sorted, written into HTML buttons, and then set as the innerHTML of a form element.

output probably looks something like this (the bracketed items represent buttons) ...

inverse by type:
[ ace ]
[ par ]
[ rar ]
[ zip ]



EZ Archive Ads Plugin for vBulletin Copyright 2006 Computer Help Forum