smitty62
asked on
Use javascript to open specific place on an accordian in other page
http://insurance.illinois.gov/defaultnew.html
I want to be able to click on the "Tax Forms" under the "Companies" dropdown menu (which is an include) and have it go to the below page with the accordion open to the tax forms part of the accordion. In other words, how do I use javascript to go to an anchor on another page with the correct expanded selection.
http://insurance.illinois.gov/Company/CompanyMain.html
I want to be able to click on the "Tax Forms" under the "Companies" dropdown menu (which is an include) and have it go to the below page with the accordion open to the tax forms part of the accordion. In other words, how do I use javascript to go to an anchor on another page with the correct expanded selection.
http://insurance.illinois.gov/Company/CompanyMain.html
ASKER
I understand the link, however, I don't understand where or how to setup the code of the second line. In classic asp you use the request command to bring in the data. Do I use an "onload=JavaScript:xxxxxxx x();" command in the body tag?
There's many ways to do it. I would start with checking the URL on page ready using the jQuery ready function:
but sure to reference jQuery if you're not already:
$( document ).ready(function() {
var myURL = window.location.href;
if (myURL.substring(myURL.length - 10, myURL.length) == '#collapse04') {
$( "#collapse04" ).addClass( "in" );
}
});
but sure to reference jQuery if you're not already:
<script src="https://cdnjs.cloudflare.com/ajax/libs/jquery/3.2.1/jquery.min.js"></script>
ASKER
Is it something like:
<script language="javascript" type="text/javascript">
function getSelected()
$( "#collapse04" ).addClass( "in" )
</script>
<body onload="javascript:getSelected();">
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
ASKER
Sorry, I responded without seeing what you wrote. Yes, I do have the jquery.min.js already referenced. Give me a few minutes to play with this a little and see if I can get what you suggested to work.
ASKER
GOT IT!!! The length just needed to be increased by one for the "#" charater.
<script language="javascript" type="text/javascript">
$( document ).ready(function() {
var myURL = window.location.href;
if (myURL.substring(myURL.length - 11, myURL.length) == '#collapse04') {
$( "#collapse04" ).addClass( "panel-collapse collapse [b]active[/b]" );
}
});
</script>
ASKER
It's working now. Thank you!
1. Include your anchor in the href:
Open in new window
2. Use javascript to uncollapse the accordian, e.g. with jQuery:Open in new window
Hope this helps!
MV