Kinda Urgent (to me, anyway) -> Javascript, postgres and checkboxes... Last big hurdle

Emma Jane Hogbin emmajane-MHIYrZpDPrNWk0Htik3J/w at public.gmane.org
Mon May 31 01:08:41 UTC 2004


On Sun, May 30, 2004 at 03:33:48PM -0400, Madison Kelly wrote:
>   Along side each directory and file is a checkbox that I have yet to 
> make work and have been struggling with for the last two days. The idea 
> is that when a checkbox for a directory is checked that automatically 
> all sub directories and files will automatically become selected. 

I don't have enough information yet to solve this problem for you....will
all files be available from the page that we're on, or just the "top level
directories" for whatever directory you're in? If all files are displayed
then this (in theory) will work. It's completely hypothetica though, so
you'll have to do some testing and let me know where it does/not work. If
the files are NOT all showing when you are trying to select sub-dirs then
you're actually working with a Perl problem, not a JavaScript problem.

Let me know how you do with this info....

So let's say your HTML looks like this:
<form name="listOfFiles" method="post" action="whatever.pl">
<input type="checkbox" name="files" value="/path/to/file/1.txt" />
<input type="checkbox" name="files" value="/path/to/file/2.txt" />
<input type="checkbox" name="files" value="/path/to/another/file/1.txt" />
<input type="checkbox" name="files" value="/path/to/another/file/again/1.txt" />
<input type="checkbox" name="files" value="/path/to/another/file/again/2.txt" />
(etc)
<input type="button" name="whatever" value="And all subdirectories"
		onclick="andLower(document.listOfFiles.files)" />

or maybe you do this onsubmit in which case:
<form name="listOfFiles" method="post" action="whatever.pl"
		onsubmit="andLower(document.listOfFiles.files)">


Then to select a "tree" of files your javascript might look something
like this:

function andLower (filesArray) {
	for (var i=0; i < filesArray.length; i++) {
		var thisFile = new String(filesArray[i].value);
		
		if (filesArray[i].checked == true) {
			// we've found an item which is currently checked
			// from here to the end of this section everything
			// should be turned "on"
			var lastSlash = thisFile.lastIndexOf("/");
			var thePath = thePath.slice(0, lastSlash);
		}

		// if this checkbox's filename starts with the checked path
		// it should also be checked
		var findMe = /^thePath/;
		if (thisFile.search(findMe) != -1) {
			filesArray[i].checked = true;
		}
	}
}



-- 
Emma Jane Hogbin
[[ 416 417 2868 ][ www.xtrinsic.com ]]
--
The Toronto Linux Users Group.      Meetings: http://tlug.ss.org
TLUG requests: Linux topics, No HTML, wrap text below 80 columns
How to UNSUBSCRIBE: http://tlug.ss.org/subscribe.shtml





More information about the Legacy mailing list