Go Back   CodingForums.com > :: Client side development > JavaScript programming > JavaScript frameworks

Before you post, read our: Rules & Posting Guidelines

Reply
 
Thread Tools Rate Thread
Enjoy an ad free experience by logging in. Not a member yet? Register.
Old 12-19-2012, 09:21 AM   PM User | #1
prajwala
New Coder

 
Join Date: Feb 2007
Posts: 67
Thanks: 7
Thanked 0 Times in 0 Posts
prajwala is an unknown quantity at this point
Question Linking html pages to the left nav menu options

I have created a .js file for left nav manu/sidebar.
I am calling this .js file in my .html page so that i dont have to write the code for left menu in each page.

Now if i click on any other link the new html file opens.but i am not able to apply the classes for nav menu on load.


Below is my code:

In my html page i have included this code

Code:
$(document).ready(function () {
$("div.sidebar").find('a').click(function(){
    $(this).parent('li').toggleClass('active');
    $(this).next("ul").slideToggle(800);
    $(this).parent('li').prevAll('li').find('ul').slideUp(800);
    $(this).parent('li').prevAll('li').removeClass('active');

    $(this).parent('li').nextAll('li').find('ul').slideUp(800);
    $(this).parent('li').nextAll('li').removeClass('active');
    //$(this).next("ul.sidebarList").slideDown(500).parent('li').siblings("ul.sidebarList").slideUp("slow");
  });

});

in body tag i have written code for left nav menu:

Code:
<!-- sidebar -->
        <div class="sidebar-wrapper grey" id="con"></div>
        <!-- Accordion Menu starts -->
			<script src="js/sidebar.js" type="text/javascript"></script>
        <!-- Accordion Menu ends -->
        <!-- sidebar -->
the .js file of sidebar/menu is given below:

Code:
document.write("<!-- sidebar -->"+
        "<div class='sidebar-wrapper grey' id='con'></div>"+
        "<!-- Accordion Menu starts -->"+
		"<div class='sidebar'>"+
            "<ul>"+
               "<li><a href='#'>Admin <span>&nbsp;</span></a>"+
                	"<ul class='sidebarList'>"+
                    	"<li class='dottedBorder'><a href='#'>Add User</a></li>"+
                        "<li><a href='#'>Find User</a></li>"+
                    "</ul>"+
                "</li>"+
                "<li><a href='#'>Manage Consumer <span>&nbsp;</span></a>"+
                	"<ul class='sidebarList' >"+
                    	"<li class='dottedBorder activeLink'><a href='#'><span style='cursor:default'>Search Consumer</span></a></li>"+
                        "<li><a href='new-connection.htm'>Add New Connection</a></li>"+
                    "</ul>"+
                "</li>"+
                "<li><a href='#'>Delivery Process <span>&nbsp;</span></a>"+
                	"<ul class='sidebarList'>"+
                    	"<li class='dottedBorder'><a href='#'>Import Delivery Allocation</a></li>"+
                        "<li><a href='#'>Manage delivery Allocation</a></li>"+
                    "</ul>"+
                "</li>"+
                "<li><a href='#'>Reports <span>&nbsp;</span></a>"+
                	"<ul class='sidebarList'>"+
                    	"<li><a href='#'>Delivery Reports</a></li>"+
                    "</ul>"+
                "</li>"+
            "</ul>"+
		"</div>"+
        "<!-- Accordion Menu ends -->"+
        "<!-- sidebar -->");
prajwala is offline   Reply With Quote
Old 12-19-2012, 09:46 AM   PM User | #2
VIPStephan
The fat guy next door


 
VIPStephan's Avatar
 
Join Date: Jan 2006
Location: Halle (Saale), Germany
Posts: 7,602
Thanks: 5
Thanked 865 Times in 842 Posts
VIPStephan is a jewel in the roughVIPStephan is a jewel in the roughVIPStephan is a jewel in the rough
Oh my, this is a terrible way to do it. Why don’t you create your entire website with JS so that people without JS enabled/available see nothing at all?

Seriously, you should look into Server Side Includes (also available in PHP and other languages).
__________________
Don’t click this link!
VIPStephan is offline   Reply With Quote
Old 12-19-2012, 09:53 AM   PM User | #3
prajwala
New Coder

 
Join Date: Feb 2007
Posts: 67
Thanks: 7
Thanked 0 Times in 0 Posts
prajwala is an unknown quantity at this point
this is clients requirement...i cant make any changes in it
prajwala is offline   Reply With Quote
Old 12-19-2012, 10:59 AM   PM User | #4
VIPStephan
The fat guy next door


 
VIPStephan's Avatar
 
Join Date: Jan 2006
Location: Halle (Saale), Germany
Posts: 7,602
Thanks: 5
Thanked 865 Times in 842 Posts
VIPStephan is a jewel in the roughVIPStephan is a jewel in the roughVIPStephan is a jewel in the rough
What exactly is the client’s requirement? That you create a menu entirely with JavaScript and insert it with document.write()?
__________________
Don’t click this link!
VIPStephan is offline   Reply With Quote
Reply

Bookmarks

Jump To Top of Thread


Thread Tools
Rate This Thread
Rate This Thread:

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off

Forum Jump


All times are GMT +1. The time now is 04:15 PM.


Advertisement
Log in to turn off these ads.