Padgoi Posted October 9, 2008 Share Posted October 9, 2008 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. Quote Link to comment Share on other sites More sharing options...
CroNiX Posted October 9, 2008 Share Posted October 9, 2008 place js in the <head> of your document. Quote Link to comment Share on other sites More sharing options...
DeanWhitehouse Posted October 9, 2008 Share Posted October 9, 2008 It can go anywhere just people put it nere the top because they will try and call the function before they have defined it. Quote Link to comment Share on other sites More sharing options...
DarkWater Posted October 9, 2008 Share Posted October 9, 2008 It can go anywhere just people put it nere the top because they will try and call the function before they have defined it. It's typically supposed to be in the <head> section. Quote Link to comment Share on other sites More sharing options...
Padgoi Posted October 9, 2008 Author Share Posted October 9, 2008 No, sorry guys, I know where to put the JS code. I don't know how to place the div around the $row['rating'] part so that the user has to click the image to show it. Any help with this? Quote Link to comment Share on other sites More sharing options...
CroNiX Posted October 9, 2008 Share Posted October 9, 2008 Should this: $this->ratings[$rrow['rating']] be this: $this->ratings($rrow['rating']) ?? Quote Link to comment Share on other sites More sharing options...
MatthewJ Posted October 9, 2008 Share Posted October 9, 2008 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 Quote Link to comment Share on other sites More sharing options...
CroNiX Posted October 10, 2008 Share Posted October 10, 2008 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. Quote Link to comment Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.