justAnoob Posted December 6, 2009 Share Posted December 6, 2009 looking to close the div on page load <div id="' . $row['item_name'] . '"> function closeall() { var divs=document.getElementById(' . $row['item_name'] . ') if(divs.style.display=='block') divs.style.display='none'; } Quote Link to comment https://forums.phpfreaks.com/topic/184135-am-i-in-the-right-direction-with-this-function/ Share on other sites More sharing options...
BenInBlack Posted December 6, 2009 Share Posted December 6, 2009 Hey, I recommend checking out JQuery, you just include this library in header and open up a new world of Javascript the next generation ;-) http://docs.jquery.com/Tutorials:Basic_Show_and_Hide in the head section place <head> <script src="js/jquery-1.3.2.min.js" type="text/javascript"></script> <script type="text/javascript"> $(document).ready(function() { $('#<?php echo $row['item_name'];?>').hide(); }); </script> </head> to show in JQuery use the .show() Hope this helps Quote Link to comment https://forums.phpfreaks.com/topic/184135-am-i-in-the-right-direction-with-this-function/#findComment-972255 Share on other sites More sharing options...
justAnoob Posted December 6, 2009 Author Share Posted December 6, 2009 actually looking for something to work in conjuction with this function, function clicked(element) { var div=document.getElementById(element) if(div.style.display=='none') div.style.display='block'; else div.style.display='none'; return; } This is the click function for my divs, right now the divs are open when the page is loaded. Looking to have them closed when the page is loaded and still be able to use the function above for the clicking. Quote Link to comment https://forums.phpfreaks.com/topic/184135-am-i-in-the-right-direction-with-this-function/#findComment-972435 Share on other sites More sharing options...
Psycho Posted December 8, 2009 Share Posted December 8, 2009 ...right now the divs are open when the page is loaded. Looking to have them closed when the page is loaded and still be able to use the function above for the clicking. So...create them as closed. Just include style="display:none;" in all of the divs by default. Then reverse the logic of your function so that it "assumes" the initial state is closed. The JavaScript style properties are not set via the inline properties. I would also modify the function to just two lines: function clicked(element) { var divObj = document.getElementById(element); divObj.style.display = (divObj.style.display=='block') ? 'none' : 'block'; return; } Quote Link to comment https://forums.phpfreaks.com/topic/184135-am-i-in-the-right-direction-with-this-function/#findComment-973470 Share on other sites More sharing options...
justAnoob Posted December 10, 2009 Author Share Posted December 10, 2009 the only div that I would like to have closed on page load is <div id="' . $row['item_name'] . '"> Wouldn't that hide every div on the page? Quote Link to comment https://forums.phpfreaks.com/topic/184135-am-i-in-the-right-direction-with-this-function/#findComment-974446 Share on other sites More sharing options...
ngreenwood6 Posted December 10, 2009 Share Posted December 10, 2009 not if you call the function that mjdamato suggests passing it the elements name or in your case $row['item_name'] so it would look like this: <script type="text/javascript"> clicked($row['item_name']); </script> Quote Link to comment https://forums.phpfreaks.com/topic/184135-am-i-in-the-right-direction-with-this-function/#findComment-974489 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.