?
Solved

How do I open a flatfile based on a drop-down selection?

Posted on 2005-03-24
6
Medium Priority
?
262 Views
Last Modified: 2006-11-17
Below I have a drop down list with items referring to data-files (flatfile).  Each flatfile contain the records that guest selected when signing the guestbook.

Given the following drop-down option

                <select size="1" name="vcat" >

      <!--[OPTIONS]-->
      <Option value="gb_Dis.dat">Disabled Access</option>
                <Option value="gb_Loc.dat">Local Information</option>
                <Option value="gb_Wea.dat">Weather</option>
                <Option value="gb_Cur.dat">Currency</option>
                <Option value="gb_Apa.dat">Apartments</option>
                <Option value="gb_Res.dat">Restaurants</option>
                <Option value="gb_Com.dat">Complex</option>
                <Option value="gb_Lei.dat">Leisure &amp; Entertainment</option>
                <Option value="gb_Act.dat">Activities for Kids</option>

              </select></td></tr>

how do I get it that the appropiate file loads and display the contents (the loading of the file is important! - variable=$datafile).  I gather an onchange event handler is required - but I just don't know how! I want the file to be loaded when I make my selection on the drop-down.

Thanks
0
Comment
Question by:JG2112
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 4
  • 2
6 Comments
 
LVL 4

Expert Comment

by:sint4x
ID: 13626797
Well if you think about it, loading files requires server side capabilities, therefore they must be loaded before the page is rendered. Thus, you need to load the files into say.. a <div> and then onchange you display the desired div and hide the rest:

Example:

<script>
lstFiles = new Array("gB_Loc.dat");

function ChangeFile( filename )  {
      for( i = 0; i <= lstFiles.length; i++ ) {
        if( filename == lstFiles[i] ) {
              document.getElementById( filename ).style.display = 'list-item';
        } else {
                        document.getElementById( filename ).style.display = 'none';

      }
}

</script>
0
 
LVL 4

Expert Comment

by:sint4x
ID: 13626836
Sry hit the wrong button on my laptop (stupid touchpad)

That script doesnt work^^

<script>
lstFiles = new Array("gB_Loc.dat"); // List all ur files here

function ChangeFile( filename )  {
     for( i = 0; i <= lstFiles.length; i++ ) {
       if( filename == lstFiles[i] ) {
             document.getElementById( filename ).style.display = 'list-item';
       } else {
             document.getElementById( filename ).style.display = 'none';
       }
     }
}

</script>

                <select size="1" name="vcat" >

     <!--[OPTIONS]-->
     <Option value="gb_Dis.dat" onChange="ChangeFile(this.value);">Disabled Access</option>
                <Option value="gb_Loc.dat">Local Information</option>
                <Option value="gb_Wea.dat">Weather</option>
                <Option value="gb_Cur.dat">Currency</option>
                <Option value="gb_Apa.dat">Apartments</option>
                <Option value="gb_Res.dat">Restaurants</option>
                <Option value="gb_Com.dat">Complex</option>
                <Option value="gb_Lei.dat">Leisure &amp; Entertainment</option>
                <Option value="gb_Act.dat">Activities for Kids</option>

              </select></td></tr>

    <!-- now u need to dynamically load your files into divs  with the corresponding filenames as the ids, make sure you have them set to hide on default -->

    <div id="gb_Loc.dat" style="display: none">gb_Loc file contents</div>

   <!-- .... other files as well -->

Hope this helps
0
 

Author Comment

by:JG2112
ID: 13626992
I tried what you said - however nothing happens after dropdown item selected! Where must the divs go - sorry but I dont know PHP - very new!!
0
WordPress Tutorial 3: Plugins, Themes, and Widgets

The three most common changes you will make to your website involve the look (themes), the functionality (plugins), and modular elements (widgets).

In this article we will briefly define each again, and give you directions on how to install them.

 
LVL 4

Expert Comment

by:sint4x
ID: 13627304
that is more javascript then php, what browser are you using?
0
 

Author Comment

by:JG2112
ID: 13629058
IE 6
0
 
LVL 4

Accepted Solution

by:
sint4x earned 200 total points
ID: 13630359
errr..

Put 'onChange="ChangeFile(this.value);">'

on the SELECT tag not the option tag.


Sorry
0

Featured Post

Want to be a Web Developer? Get Certified Today!

Enroll in the Certified Web Development Professional course package to learn HTML, Javascript, and PHP. Build a solid foundation to work toward your dream job!

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

This article discusses four methods for overlaying images in a container on a web page
Originally, this post was published on Monitis Blog, you can check it here . In business circles, we sometimes hear that today is the “age of the customer.” And so it is. Thanks to the enormous advances over the past few years in consumer techno…
The viewer will learn how to dynamically set the form action using jQuery.
The viewer will learn how to count occurrences of each item in an array.
Suggested Courses

762 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question