justAnoob Posted November 12, 2009 Share Posted November 12, 2009 <SCRIPT TYPE="text/javascript"> function closeall() { var divs=document.getElementsByTagName('div') for(var i=0; i<divs.length; i++) divs[i].style.display='none'; } function clicked(element) { var div=document.getElementById(element) if(div.style.display=='none') div.style.display='block'; else div.style.display='none'; return; } </script> <?php echo 'My'; echo '<div id="My">'; while ($row = mysql_fetch_array($sql)) { ?> <div id="trade"> <li> <?php echo '<a href="#" onclick="clicked(' . $row['item_name'] . ')">' . $row['item_name'] . '</a>'; ?> </li> <li> <?php echo '<img src="' . $row['thumb_1'] . '" width="100" alt="" />'; ?> </li> </div> <?php } echo "</div>"; ?> found some functions online that work great for a tree menu, but when i have a little php in with the menu (so i can pull info from db) it seems to throw off the javascript functions. Can you see what is wrong? I'm guessing that the js cannot be inside the php like that. Quote Link to comment Share on other sites More sharing options...
justAnoob Posted November 12, 2009 Author Share Posted November 12, 2009 just figured it out, will post up soon. thanks. Quote Link to comment Share on other sites More sharing options...
justAnoob Posted November 12, 2009 Author Share Posted November 12, 2009 ok, maybe it is not working, sorry guys. here is the problem, again. this works, meaning my function works <a href="#" onclick="clicked('name')">name</a> but for the name i want to pull it from the db, which is not correctly executed below. <?php echo '<a href="#" onclick="clicked(' . $row['item_name'] . ')">' . $row['item_name'] . '</a>'; ?> Anyone? Quote Link to comment Share on other sites More sharing options...
justAnoob Posted November 12, 2009 Author Share Posted November 12, 2009 Here is all the code again. function clicked(element) { var div=document.getElementById(element) if(div.style.display=='none') div.style.display='block'; else div.style.display='none'; return; } <?php echo 'My'; echo '<div id="My">'; while ($row = mysql_fetch_array($sql)) { ?> <div id="trade"> <li> <?php echo '<a href="#" onclick="clicked(' . $row['item_name'] . ')">' . $row['item_name'] . '</a>'; ?> </li> <div id="item name"> <?php echo '<img src="' . $row['thumb_1'] . '" width="100" alt="" />'; ?> </div> </div> <?php } echo "</div>"; ?> Quote Link to comment Share on other sites More sharing options...
justAnoob Posted November 12, 2009 Author Share Posted November 12, 2009 bump, Spent a good part of the night trying to figure this out. I'm stumped. <?php echo '<a href="#" onclick="clicked(' . $row['item_name'] . ')">' . $row['item_name'] . '</a>'; ?> Quote Link to comment Share on other sites More sharing options...
DavidAM Posted November 12, 2009 Share Posted November 12, 2009 In your "working" example, there are quotes around the name. But when you changed it to the echo, they got left out. Don't you need them so JS will see the string rather than a variable name? echo '<a href="#" onclick="clicked(\'' . $row['item_name'] . '\')">' . $row['item_name'] . '</a>'; Quote Link to comment Share on other sites More sharing options...
justAnoob Posted November 12, 2009 Author Share Posted November 12, 2009 Thanks DavidAM. So far so good. 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.