Jump to content

Implementing Javascript Hide/Show into PHP


Padgoi

Recommended Posts

I have this PHP code:

 

           $row['ratings'] = "";


                        $ratingsSQL = $this->ipsclass->DB->query(
                                                                "SELECT `pid` , `rating` , COUNT(`rating`) as ratings
                                                                FROM `ibf_ratings`
                                                                WHERE `pid` = '" . $row['pid'] . "' GROUP BY `rating`
                                                                ");

                        $i = 0;
                        $ratingshtml = "";

                        if( $this->ipsclass->DB->get_num_rows( $ratingsSQL ) )
                        {
                                while( $rrow = $this->ipsclass->DB->fetch_row( $ratingsSQL ) )
                                {
                                        $ratingshtml .= "<div class=\"rate_it_display\" style=\"background-image: url( 'style_images/rate/" . str_replace( ' ' , '' , strtolower( $this->ratings[$rrow['rating']] ) ) . ".png' ) \"> " . $rrow['ratings']. " x " . $this->ratings[$rrow['rating']] . "!</div>";
                                        $i++;
                                }

                                $ratingshtml .= "<a href=\"#\" onclick=\"return RateItExpand( {$row['pid']} );\" style=\"color: #999;\">(list)</a>";

                        }

                        $row['ratings'] = $this->ipsclass->compiled_templates['skin_topic']->ratings( $row['pid'] , $row['author_id'] , $ratingshtml );
       

 

I want to input a Javascript Onclick Hide/Show function like this into the $row['ratings'] part so that the user has to click an image to show the available ratings:

<script type="text/javascript">
<!--
    function toggle_visibility(id) {
       var e = document.getElementById(id);
       if(e.style.display == 'block')
          e.style.display = 'none';
       else
          e.style.display = 'block';
    }
//-->
</script>
<a href="#" onclick="toggle_visibility('foo');"><img src="myimage"></a>
<div id="foo">This is foo</div>

 

Any help with this?  I'm not sure where to put the Javascript code. 

It is "recommended" that it be put in the head so it is completely loaded before anything in the page can call it... "supposed to be" makes it sound like a rule :)

 

 

That wouldn't be true unless you were running the code thats in the head with a onload event attached to the body.  It IS completely loaded when the head is read, and that loads before your page.  So you don't want to execute it until the body is loaded.

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.