How to display content on select item?

Discussion in 'PHP' started by KingCobra, May 5, 2012.

  1. #1
    I have a very simple php file where just have a html dropdown list. (see image part-1)

    I need to display contents (see image part-2) on same page (mabe without page reload) when select any item from select box.
    (content of part2 will change based on selection)

    02.gif

    Part-2 portion of the image will come from a .txt file.
    I can show that text file like this way:

    <?php include('one.txt'); ?>
    or
    <?php include('two.txt'); ?>

    I don't know how to load/display another files content based on selection.

    Please help me.
     
    KingCobra, May 5, 2012 IP
  2. infotripro

    infotripro Member

    Messages:
    26
    Likes Received:
    2
    Best Answers:
    1
    Trophy Points:
    43
    #2
    at least two options:

    1) php - ochange="action script which change a $_SESSION variable storing the selected index"
    2) load all descriptions and show/hide them in javascript (easier with jQuery)
     
    infotripro, May 5, 2012 IP
  3. infotripro

    infotripro Member

    Messages:
    26
    Likes Received:
    2
    Best Answers:
    1
    Trophy Points:
    43
    #3
    <select id="category" onchange="change_index()">
    <option value='0'>-choose a category-</option>
    <option value='1'>ONE</option>
    <option value='2'>two</option>
    <option value='3'>three</option>​
    </select>

    <div id="description0" style="display:none;">please select a category!</div>
    <div id="description1" style="display:none;">description category 1!</div>
    <div id="description2" style="display:none;">description category 2!</div>
    <div id="description3" style="display:none;">description category 3!</div>



    function change_index(){
    var idx=document.getElementById('category').selectedIndex;
    var descriptions = document.getElementsByTagName("div");
    for(var i = 0; i < descriptions.length; i++) {
    if(descriptions.name.indexOf('description')==0) {

    if(i==idx){
    document.getElementById('descriptions').style.display="block";

    }else{
    document.getElementById('descriptions').style.display="none";

    }​
    }​
    }​
    }

    and if you have other divs on your page you have to work a little bit harder
     
    infotripro, May 5, 2012 IP
    Imless likes this.