location.href script

Discussion in 'Javascript' started by wannieb, Mar 1, 2006.

  1. wannieb

    wannieb Guest

    I am hoping someone can help me in this little problem, I have a php
    page with dynamic menu boxes on it.

    SCRIPT
    *********
    <!-- Below are arrays for the two dropdown menus and creates selected
    variables so that the selection is seen when posted -->
    <?php
    $dop = array(
    "nbr/2001" => "2001",
    "nbr/2002" => "2002",
    "nbr/2003" => "2003",
    "nbr/2004" => "2004",
    "nbr/2005" => "2005",
    "nbr/2006" => "2006"
    );
    $dsop = array(
    "/q1nb" => "First Quarter",
    "/q2nb" => "Second Quarter",
    "/q3nb" => "Third Quarter",
    "/q4nb" => "Fourth Quarter",
    );

    $stickydop = '';
    if(isset($_POST['submit'])) {
    $stickydop = $_POST['dropdown1'];
    }
    $stickydsop = '';
    if(isset($_POST['submit'])) {
    $stickydsop = $_POST['dropdown2'];
    }
    ?>
    <!-- End of variable set up -->

    <!-- Form consisting of a menu boxes containing the folder arrays from
    above, putting selected choice when form is posted -->
    <form method="post" name="pickdir">
    <select name="dropdown1">
    <option value="">Select One</option>
    <?php
    foreach ($dop as $key => $value){
    if($key == $stickydop) {
    echo '<option value="' . $key .'" selected>' . $value .
    '</option>';
    }
    else{
    echo '<option value="' . $key .'">' . $value . '</option>';
    }
    }
    ?>
    </select>
    <select name="dropdown2">
    <option value="">Select One</option>
    <?php
    foreach ($dsop as $key => $value){
    if($key == $stickydsop) {
    echo '<option value="' . $key .'" selected>' . $value .
    '</option>';
    }
    else{
    echo '<option value="' . $key .'">' . $value . '</option>';
    }
    }
    ?>
    </select>
    <input type="submit" name="submit" value=">>">
    <form>
    <!-- End of Form -->

    <!-- Below produces an array of all file names, which sit within the
    directory from the above menu boxes -->
    <?php
    // The variable below connects the two select menus above into one
    path
    $dirfile = $dropdown1.$dropdown2;
    // The variable below makes only the file extensions listed visible
    $pattern = "(\.html$)|(\.htm$)";

    if($dir=@opendir($dirfile)){
    while(($file=readdir($dir))!==FALSE){
    if($file=='..' || $file=='.') continue;
    // Registers just the files with the extension listed
    if(eregi($pattern,$file))
    // Creates array of files with in the folder
    $filelist[]=$file;
    }
    closedir($dir);
    }
    ?>
    <!-- End of finding files -->

    <!-- Form consisting of a menu box containing the file array from above
    -->
    <br><br>
    <form name="jump2file">
    <select name="ofile">
    <?php
    asort($filelist);
    foreach($filelist as $val){
    // $valnoext will strip from view the file extensions of the files
    in the list
    $valnoext = str_replace(array('.html','.htm'),'',$val);
    // $dirfile has been put in here so that the javascript picks up the
    folder as well as the file name to open
    echo '<option value=',$dirfile,'/',$val,'>',$valnoext,'</option>';
    }
    ?>
    </select> <br><br>
    <input type="button" value="Open" ONCLICK="Jump()">
    </form>
    <!-- End of Form -->

    <!-- Script takes selected file and opens up in window -->
    <script>function Jump()
    {
    location.href = document.jump2file.ofile.value;
    }
    </script>
    <!-- End of script -->
    ********

    I have put echos in the script when testing to make sure the correct
    information goes in the php variables, which they all do. The problem
    comes when clicking on the final button : <input type="button"
    value="Open" ONCLICK="Jump()">

    Which runs the javascript, it no longer works, it says
    'document.jump2file.ofile' is Null or not an object.

    can anyone see where this is going wrong.
     
    wannieb, Mar 1, 2006
    #1
    1. Advertising

  2. wannieb

    VK Guest

    wannieb wrote:
    > <script>function Jump()
    > {
    > location.href = document.jump2file.ofile.value;
    > }
    > </script>


    I did not go through the all script, but schouldn't it be:

    location.href =
    document.jump2file.ofile[document.jump2file.ofile.selectedIndex].value;
     
    VK, Mar 1, 2006
    #2
    1. Advertising

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

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. CRON
    Replies:
    24
    Views:
    200,850
    Adrienne Boswell
    Jun 20, 2006
  2. Soren Vejrum
    Replies:
    4
    Views:
    630
    Lasse Reichstein Nielsen
    Jul 5, 2003
  3. saiho.yuen
    Replies:
    3
    Views:
    437
    kaeli
    Sep 14, 2004
  4. Replies:
    2
    Views:
    482
  5. Alex Bird
    Replies:
    3
    Views:
    189
    Thomas 'PointedEars' Lahn
    May 9, 2008
Loading...

Share This Page