Slight problem with script

W

wannieb

I am having difficulties with a script I am creating. Most of the
script is PHP however I have a javascript to open a window at the end,
which is not picking up the variables.

The script is suppose to show in the first menu box a list of folder
names from a certain place.
On clicking on the submit button it populates the second menu box with
the folders within that folder, when clicking on final button, it opens
that page in new window.

Script below:

******
<?php
// Below produces an array of all folder names, which sit within the
$DirectoriesToScan variable
$DirectoriesToScan = array('nb');
$DirectoriesScanned = array();

while (count($DirectoriesToScan) > 0) {
foreach ($DirectoriesToScan as $DirectoryKey => $startingdir) {
if ($dir = @opendir($startingdir)) {
while (($file = readdir($dir)) !== false) {
if (($file != '.') && ($file != '..')) {
$RealPathName = ($startingdir.'/'.$file);
if (is_dir($RealPathName)) {
if (!in_array($RealPathName, $DirectoriesScanned) &&
!in_array($RealPathName, $DirectoriesToScan)) {
$DirectoriesToScan[] = $RealPathName;
$DirList[] = $RealPathName;
}
}
}
}
closedir($dir);
}
$DirectoriesScanned[] = $startingdir;
unset($DirectoriesToScan[$DirectoryKey]);
}
}

?>
<!-- Form consisting of a menu box containing the folder array from
above -->
<form name="jumpfile">
<select name="odir">
<?php
asort($DirList);
foreach($DirList as $val){
echo '<option value=',$val,'>',$val,'</option>';
}
?>
</select>
<input type="submit" name="Submit" value="Go to">
</form>
<!-- End of Form -->
<?php
// Below produces an array of all file names, which sit within the
directory from the above menu box
if($dir=@opendir($odir)){
while(($file=readdir($dir))!==FALSE){
if($file=='..' || $file=='.') continue;
$filelist[]=$file;
}
closedir($dir);
}
echo "$odir";
?>
<!-- Form consisting of a menu box containing the file array from above
-->
<form name="jumpfile">
<select name="openfile">
<?php
asort($filelist);
foreach($filelist as $val){
echo '<option
value=',$odir,'/',$val,'>',$val,'</option>';
}
?>
</select>
<input type="button" value="GO" ONCLICK="Jump()">
</form>
<!-- End of Form -->
<script>function Jump()
{
location.href = document.jumpfile.openfile.value;
}
</script>
******

With regards to the PHP I want some small alterations to get the
desired look which I don't know how to achieve
Instead of seeing the whole realpath of the folders, I want to just see in the menu box the folder names.
Instead of seeing the file extensions in second menu box i just want the main filename.

The script populates each menu box now however the onclick does not
work, it gives an error
"'document.jumpfile.openfile.value' is null or not an object", which I
do not understand.

This script originally I had written as:

******

<form method="get">
<select name="odir">
<option value="nb/q1nb">Jan-Mar 06</option>
<option value="nb/q2nb">Apr-Jun 06</option>
<option value="nb/q3nb">Jul-Sep 06</option>
</select>
<input type="submit" name="Submit" value="Go to">
</form>
<?php
if($dir=@opendir($odir)){
while(($file=readdir($dir))!==FALSE){
if($file=='..' || $file=='.') continue;
$filelist[]=$file;
}
closedir($dir);
}
?>


<form name="jumpfile">
<select name="openfile">
<?php
asort($filelist);
foreach($filelist as $val){
echo '<option
value=',$odir,'/',$val,'>',$val,'</option>';
}
?>
</select>
<input type="button" value="GO" ONCLICK="Jump()">
</form>
<script>function Jump()
{
location.href = document.jumpfile.openfile.value;
}
</script>
******

The javascript works on this one fine, however when I change it to the
part I want it stops working, it seems like the variables are going
correctly through the document. Does anyone have any ideas where I gone
wrong.

Can anyone help me with these three problems

Thanks
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
473,755
Messages
2,569,536
Members
45,013
Latest member
KatriceSwa

Latest Threads

Top