Hello and welcome to our community! Is this your first visit?
Register
Enjoy an ad free experience by logging in. Not a member yet? Register.
Results 1 to 2 of 2
  1. #1
    New to the CF scene
    Join Date
    May 2006
    Posts
    1
    Thanks
    0
    Thanked 0 Times in 0 Posts

    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 04:24 PM.

  • #2
    New Coder
    Join Date
    May 2006
    Posts
    19
    Thanks
    0
    Thanked 0 Times in 0 Posts
    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 ]


  •  

    Posting Permissions

    • You may not post new threads
    • You may not post replies
    • You may not post attachments
    • You may not edit your posts
    •