I’m really new to Javascript and I’m having some trouble understanding how to get the following to work. My goal is to have a certain Javascript action execute when a page loads and a variable added to the end of the URL would trigger which Javascript action to execute. The URL of the page that I’m looking to implement this on is http://www.morgantoolandsupply.com/catalog.php. Each of the “+expand” buttons, which are Javascript driven, drop-down a certain area of the page. Ultimately, I would like to be able to create a URL that would automatically drop-down a certain category when the page loads. Could anybody explain to me the process to do this? Thanks in advance for any help!
I’m really new to Javascript and I’m having some trouble understanding how to get
Share
You’ve already got the function to call:
toggle2(), which takes two parameters that happen to be identical for all categories except for a number at the end. So create a URL that includes that number: http://www.morgantoolandsupply.com/catalog.php#cat=4Then find that number in
location.hashusing a regular expression. This one is robust enough to handle multiple url parameters, should you decide to use them in the future:/[\#&]cat=(\d+)/. But, if you expect to never add anything else to the url, you could use a very simple one like/(\d+)/.Once you’ve got the number, it’s a simple matter of using that number to create your two parameters and calling
toggle2().This should work: