Facebook   Twitter    e-mail newsletter    YouTube    RSS Feed    Android App    iPhone and iPad App     BlackBerry App    


Results 1 to 8 of 8

Thread: Dynamic HTML\JavaScript keeps breaking when echoed from PHP

  1. #1

    Default Dynamic HTML\JavaScript keeps breaking when echoed from PHP

    I have found a little script online which has a nice expanding and collapsing TABLE effect. I am trying to build a display for a mailbox, the result will be echoed from PHP to dynamically create all the rows from a MySQL DB.
    When a user clicks on a email subject 'Toggle' it should slide down to display the email where 'Test row' is.

    The script works fine until echoing it. Is what I'm trying to do possible with the below script, I'm not to clued up on the JavaScript side of things so I'm not sure why it's breaking.

    Any other recommendations would be appreciated.

    I haven't pasted my code as I have been through to many variations(non worked).. :/

    Code:
    <html>
    <head>
        <title> New Document </title>
    </head>
    <body>
    
    <table width="400">
        <tbody>
            <tr><td style="background-color: #CCC"><a href="#" onclick="toggleItem('myTbody')">Toggle</a></td></tr>
        </tbody>
    
        <tbody id="myTbody">
            <tr><td>Test row1</td></tr>
            <tr><td>Test row2</td></tr>
            <tr><td>Test row3</td></tr>
            <tr><td>Test row4</td></tr>
            <tr><td>Test row5</td></tr>
        </tbody>
    </table>
    
    </body>
    </html>   
    <script language="javascript">
        function getItem(id)
        {
            var itm = false;
            if(document.getElementById)
                itm = document.getElementById(id);
            else if(document.all)
                itm = document.all[id];
            else if(document.layers)
                itm = document.layers[id];
    
            return itm;
        }
    
        function toggleItem(id)
        {
            itm = getItem(id);
    
            if(!itm)
                return false;
    
            if(itm.style.display == 'none')
                itm.style.display = '';
            else
                itm.style.display = 'none';
    
            return false;
        }
    </script>

  2. #2

    Default

    Can you post the php code?

    using Jquery show might be easier: http://api.jquery.com/show/

  3. #3

    Default

    This works as expected but looses all dynamic ability's.. Will have a look at your link.. ta

    Code:
    <?PHP
    $sql="SELECT * FROM `$tbl_3` ORDER BY id DESC";
    $result = mysql_query($sql);
    $a = 1;
    while ($row=mysql_fetch_row($result))
    {
    ?>
    <TR><TD style='background-color:#CCC'>
    <?PHP
    echo "<a href=messenger.php onclick='toggleItem(myTbody_".$a.")'>".$row[3]."</a>";
    ?>
    </TD></TR>
    <?PHP
    echo "<tbody id='myTbody_".$a."'><tr><td>".$row[4]."</td></tr></tbody>";
    $a ++;
    }
    ?>

  4. #4

  5. #5

    Default

    Thanks guys those are both very cool, Ill play around with them

  6. #6

    Default

    have you tried the jquery ui functions?

    Something like accordian - http://jqueryui.com/demos/accordion/

  7. #7

    Default

    Quote Originally Posted by rward View Post
    have you tried the jquery ui functions?

    Something like accordian - http://jqueryui.com/demos/accordion/
    No I haven't only just starting to look into JQuery and such for a recent project. I used to do a little bit of VBScript and JavaScript back in the day, nothing complexed thou. JQuery looks awesome, think I'm going to have to start paying it more attention.. Thanks so much again guys, these are just what I was looking for. It's going to look amazing..

  8. #8

    Default

    I haven’t seen enough code but
    If what you are showing does not exist (in the DOM)when the document loads you need to use .delegate to attached the handler event.

    Description: Attach a handler to one or more events for all elements that match the selector, now or in the future, based on a specific set of root elements.

    Deletegate is depreciated and replaced with .on but its easiser to get working

Similar Threads

  1. javascript
    By Philgenius in forum Software and Web Development
    Replies: 14
    Last Post: 19-06-2012, 11:34 AM
  2. HTML/CSS preventing floated elements from breaking out of parents?
    By redarrow in forum Software and Web Development
    Replies: 10
    Last Post: 26-02-2010, 12:02 PM
  3. JavaScript
    By PseudZ in forum Software and Web Development
    Replies: 1
    Last Post: 22-08-2008, 02:47 AM
  4. Javascript Help
    By RVFmal in forum Software and Web Development
    Replies: 8
    Last Post: 24-09-2007, 08:11 PM
  5. Can anyone tell me what does this javascript do?
    By PearlJam in forum Software and Web Development
    Replies: 3
    Last Post: 14-09-2007, 06:25 AM

Bookmarks

Bookmarks

Posting Permissions

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