Go Back   CodingForums.com > :: Client side development > JavaScript programming

Before you post, read our: Rules & Posting Guidelines

Reply
 
Thread Tools Rate Thread
Enjoy an ad free experience by logging in. Not a member yet? Register.
Old 05-06-2006, 02:18 PM   PM User | #1
kapone_pt
New to the CF scene

 
Join Date: May 2006
Posts: 1
Thanks: 0
Thanked 0 Times in 0 Posts
kapone_pt is an unknown quantity at this point
innerHTML Javascript Function

Hi All,


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

Code:
$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;
	}
}

Last edited by kapone_pt; 05-06-2006 at 03:24 PM..
kapone_pt is offline   Reply With Quote
Old 05-07-2006, 05:11 PM   PM User | #2
mensa_dropout
New Coder

 
Join Date: May 2006
Posts: 19
Thanks: 0
Thanked 0 Times in 0 Posts
mensa_dropout is an unknown quantity at this point
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 ]
mensa_dropout is offline   Reply With Quote
Reply

Bookmarks

Jump To Top of Thread


Thread Tools
Rate This Thread
Rate This Thread:

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off

Forum Jump


All times are GMT +1. The time now is 06:00 PM.


Advertisement
Log in to turn off these ads.