www.webdeveloper.com
Results 1 to 4 of 4

Thread: Changing the content of a table with a drop down menu

  1. #1
    Join Date
    Apr 2006
    Posts
    219

    Changing the content of a table with a drop down menu

    Hi everybody,

    I have a table giving information and prices of some products. I want the content in the table cells change when I change the product name from the drop down menu. Does anybody have an example for that?

    Thanks
    telmessos

  2. #2
    Join Date
    Nov 2007
    Posts
    20
    Cool I just did that like 2 weeks ago!

    I attached the file to the script!
    Attached Files Attached Files

  3. #3
    Join Date
    Apr 2006
    Posts
    219
    Scooby the code you sent is PHP not javascript I am looking for a javascript code which changes the content of the table cells when you change a drop down thanks

  4. #4
    Join Date
    Nov 2007
    Posts
    20
    I'm sorry, This should work.

    I don't know very much javascript so it might be incorrect but here it is.

    PHP Code:
    <script type="text/javascript">
    var 
    peoplevar "<th>Name: </th><th>Age: </th><tr><td>ScoobyDooobyD00</td><td>14</td></tr>";

    var 
    numbervar "<tr><td>1234567890</td></tr>";
    function 
    changeContent(idchanger) {
        if(
    changer == "people") {
            
    document.getElementById(id).innerHtml "" peoplevar "";
        }else if(
    changer == "numbers") {
            
    document.getElementById(id).innerHtml "" numbervar "";
        }
    </script>

    <select onChange="changeContent('mytable', this.value)">
    <option value="people">People</option>
    <option value="numbers">Numbers</option>
    </select><br />
    <table border="1" id="mytable">
    <tr>
    <td>Choose an option above!</td>
    </tr>
    </table> 

Thread Information

Users Browsing this Thread

There are currently 1 users browsing this thread. (0 members and 1 guests)

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
HTML5 Development Center



Recent Articles