Creating menus within menus - html

I'm working on a website at the minute for a project I am doing. I need to create a dropdown menu within a dropdown menu. It is part of a form. Basically its for damage to a car. In my drop down menu I have options for no damage and damage. When I select damage I need it to bring me to another form where I can select the part of the car and type in the damage. THen it needs to save. I may have worded this badly. If anyone can give me any help thta would be great
Here is what I have at the moment
Damage:<br>
<select id="test" name="form_select" onchange="showDiv(this)">
<option value="0">No</option>
<option value="1">Yes</option>
</select>
<div id="hidden_div" style="display:none;"><br>
<input type='textarea' class='text' name='hidden style' value size='20' />
</div>
<script type="text/javascript">
function showDiv(select){
if(select.value==1){
document.getElementById('hidden_div').style.display = "block";
} else{
document.getElementById('hidden_div').style.display = "none";
}
}
</script><br><br>
This gives me a text box to enter the damage into. What I would really like is to be able to get another form whcih gives me further options to select from if this is possible
eg right front
rear left

You need to create 3 level of ul
<ul id="menu">
<li><span>Level 1-A</span>
<ul>
<li><span>Level 2-A-1</span>
<ul>
<li><span>Level 3-A-1</span></li>
<li><span>Level 3-A-2</span></li>
<li><span>Level 3-A-3</span></li>
</ul>
</li>
<li><span>Level 2-A-2</span></li>
<li><span>Level 2-A-3</span></li>
<li><span>Level 2-A-4</span></li>
</ul>
</li>
<li><span>Level 1-B</span></li>
<li><span>Level 1-C</span></li>
<li><span>Level 1-D</span></li>
<li><span>Level 1-E</span></li>
Here is an example of nested dropdown menu, hope it helps.
http://jsfiddle.net/Wss5A/

Related

Dynamically updated menubar divided in categories

On my website, I want to make a navigation bar just like this, with categories (here 2012) and articles (here May - October). I've got a JSON object with all categories (id, name) and one with all articles (id, title, body, category), which angular gets for me.
The current HTML is as follows:
<!-- The angular controllers are already initialized before this piece of code -->
<div class="menubar">
<ul>
<li class="cat" ng-repeat="infocategory in info.infocategories">
{{infocategory.name}}
<ul>
<li class="arti" ng-repeat="infoentry in info.infoentries">
<!-- The link links to a function that sets the correct tab -->
<a href ng-click="tab.setTab({{infoentry.id}})">{{infoentry.title}}</a>
</li>
</ul>
</li>
</ul>
</div>
And the JavaScript:
app.controller('InfoController', ['$http', function($http){
var info = this;
info.infocategories = [];
info.infoentries = [];
// This all works correctly
$http.get(api + 'info_categories?pageSize=20&pageNumber=1').success(function(data){
info.infocategories = data.data;
});
$http.get(api + 'info_posts?pageSize=20&pageNumber=1').success(function(data){
info.infoentries = data.data;
});
}]);
However, as you can imagine, this code displays all entries under the categories, but I want only the entries that belong to the specific category to be displayed.
I'm relatively new to AngularJS, so any help is greatly appreciated. If there's any code lacking or unclear, please tell me. Thanks in advance!
Never mind, I already fixed it myself. I guess I was thinking too difficult...
<div class="menubar">
<ul>
<li class="cat" ng-repeat="infocategory in info.infocategories">
{{infocategory.name}}
<ul>
<li class="arti" ng-repeat="infoentry in info.infoentries" ng-show="infoentry.cat == infocategory.id">
<a href ng-click="tab.setTab(infoentry.id)">{{infoentry.title}}</a>
</li>
</ul>
</li>
</ul>
</div>

Opening jsp pages in an iframe from a drop-down menu

I'm creating an application in jsp & servlet. So I have created a home.jsp page it is a main page of an application and it contains a menu bar . When user clicks on menu item the following page should appear in my iframe and if user clicks on another menu item the selected page should appear in the same iframe.
I need a help.... The following code is creating a menu bar and menu item
<li>Master
<ul>
<li>Customer</li>
<li>Suplier</li>
<li>Item</li>
</ul>
</li>
<li>Transaction
<ul>
<li>Purchase</li>
<li>Sales</li>
</ul>
</li>
<li>Contact</li>
After menu bar I have a iframe in which I want to show a menu item.
I don't know how do i do this. please help me out
You will need to bind a function onclick of your <a> tag. Then using jQuery find the href of the <a> which is clicked, finally assign that href as src of your iframe
HTML
<li>Master
<ul>
<li>Customer</li>
<li>Suplier</li>
<li>Item</li>
</ul>
</li>
<li>Transaction
<ul>
<li>Purchase</li>
<li>Sales</li>
</ul>
</li>
<li>Contact</li>
<br />
<iframe src="" height="300" width="500"></iframe>
jQuery
$(document).ready(function () {
$('a').click(function () {
var target = $(this).attr('href');
$('iframe').attr('src', target);
return false;
});
});
Here's a working DEMO. I just changed the href of first two items as example.

Tabs open according to links on sub menu

In my main navigation bar there is a menu named category & item and it has two submenus which names are category and item respectively. I have only one page to display these two section.
My page is category_item.php and it has two different tabs to display each sections. In this case it is category and item.
So my problem is I need to open category and item tab when clicking on category and item links on the submenu.
UPDATE -
This is code from main navigation bar
<li class="current">
<a>Category & Item</a>
<div class="menu-container">
<div class="menu-link">
Category
</div>
<div class="menu-link current">
Item
</div>
</div>
</li>
This is from category_item.php page
<div class="ui-widget-header ui-corner-top">
<ul>
<li>My Category</li>
<li>My Items</li>
</ul>
</div>
<div id="tabs-1" class="tabs3">
my stuff...
</div>
<div id="tabs-21" class="tabs3">
my stuff...
</div>
Can I know is it possible to do?
Thank you.
You can do this using Javascript. Just toggle property display of that class from none to block and vice versa.
If you are using jQuery, you can do this:
$(document).ready(function() {
$('#cat_link').click(function() {
$('#tabs-1').hide();
$('#tabs-2').show();
return false;
});
$('#item_link').click(function() {
$('#tabs-2').hide();
$('#tabs-1').show();
return false;
});
});
You also have jQuery-UI widget tabs.
If you are using pure javascript, you can do it like this (reference):
function hideshow(which){
if (!document.getElementById)
return
if (which.style.visibility=="visible")
which.style.display="hidden"
else
which.style.display="visible"
}

how to keep toggle state after page refresh

I have expandable menu, you can see the code in this link..
my question is how can I keep toggle state after page refresh.
Thanks for your helps.
How about save it in a session variable?
Session("TopMenuState") = XYZ
where XYZ is your state info
Update
Mmmmm I will try and explain best I can with my limited amount of Javascript skills.
To check if local storage/session storage is available as follows
if(typeof(Storage)!=="undefined")
{
// localStorage and sessionStorage supported
}
else
{
// localStorage and sessionStorage NOT supported
}
Once your satisfied that local storage will be available then you can continue with coding the actual scripts, otherwise, one would assume that maybe the code will not work?
Further more when the user clicks on a link in your sliding menu, the idea is to persist the NAME of the menu he/she clicked on, and when the page loads, or when you render your menu's you can check the session/local storage to see what menu item (if any) was clicked on
So in the links in sliding menu you may end up with something along the lines of :
<div class="menuContent">
<a class="slider"><img alt="" id="bot" src="images/arrow_bottom.png"></a>
<ul id="nav">
<li><img src="images/t1.png" /> Home</li>
<li>
<ul id="1">
<li><img src="images/empty.gif" />Link 1</li>
<li><img src="images/empty.gif" />Link 2</li>
<li><img src="images/empty.gif" />Link 2</li>
<li><img src="images/empty.gif" />Link 3</li>
<li><img src="images/empty.gif" />Link 4</li>
</ul>
// THIS LINE MODIFIED
<span onclick="ProcessMenuLink('MenuItem1')" class="sub" tabindex="1"><img src="images/t2.png" />HTML/CSS</span>
</li>
<li>
<ul id="2">
<li><img src="images/empty.gif" />Link 6</li>
<li><img src="images/empty.gif" />Link 7</li>
<li><img src="images/empty.gif" />Link 8</li>
<li><img src="images/empty.gif" />Link 9</li>
<li><img src="images/empty.gif" />Link 10</li>
</ul>
// THIS LINE MODIFIED
<span onclick="ProcessMenuLink('MenuItem2')" class="sub" tabindex="1"><img src="images/t3.png" />jQuery/JS</span>
</li>
<li><img src="images/t2.png" />PHP</li>
</ul>
</div>
PLEASE NOTE: My javascript skills arelimited so you may need to check this code!
It is most likely missing a semicolon here and there.
And then in the subroutine or function you may have something along the lines of:
Void ProcessMenuLink(MenuItemId){
if(typeof(Storage)!=="undefined")
{
// localStorage and sessionStorage supported
//If the menuitem selected is valid
if (MenuItemId == 1) Then
{
//Save the selected menu ID/Name
localStorage.MySelectedMenuItem=MenuItemId;
// OPTIONAL - Call the toggle subroutine to toggle the selected menuitems
// Code to call sliding routine if its not executed via the CLASS parameter
}
}
else
{
// localStorage and sessionStorage NOT supported
}
}
Now at this point you have saved the SELECTED MENU ITEM in the local storage and I assume the page reloads.
So when your page loads you will want to call the subroutine which performs the menu animation or SLIDING and pass it relevant value based upon the locally-stored selected menuitem value.
Sub Window.OnLoad
//load locally stored data
if (localStorage.MySelectedMenuItem == 'MenuItem1')
{
// menu item with id 'MenuItem1' was selected so call the sliding routine
// using whatever value you used to identify your first sliding menu
}
else
{
if (localStorage.MySelectedMenuItem == 'MenuItem2')
{
// menu item with id 'MenuItem2' was selected so call the sliding routine
// using whatever value you used to identify your first sliding menu
}
else
{
// nothing was selected or an invalid selection was specified
// show the menu items in their DEFAULT state
}
}
End Sub
I'm not completely sure how to call/execute the function as its all in Javascript
Well I can only apologise for my weak Java skills coming from a VB background,
but i hope you got the gist of my meaning and that it helps you address your issue.

Bootstrap collapse data-parent not working

I'm using bootstrap 2.2.1 and for whatever reason the data-parent attribute is not doing what is intended. It does not close a previous opened target when i click another target. Here's a fiddle with the code below, any ideas on how to fix this ?
<div id="accordion">
<ul>
<li>
<a href="#" data-toggle='collapse' data-target='#document', data-parent='#accordion'>option 1</a>
<ul id="document" class="collapse">
<li> suboption 1</li>
<li> suboption 1</li>
<li> suboption 1</li>
</ul>
</li>
<li>
option 2
</li>
<li>
option 3
</li>
<li>
<a href="#" data-toggle='collapse' data-target='#document2', data-parent='#accordion'>option 4</a>
<ul id="document2" class="collapse">
<li> suboption 1</li>
<li> suboption 1</li>
<li> suboption 1</li>
</ul>
</li>
</ul>
</div>
It says in the Bootstrap Documents:
If a selector is provided, then all collapsible elements under the
specified parent will be closed when this collapsible item is shown.
(similar to traditional accordion behavior - this is dependent on the
panel class)
so it has to be used with panel-groups, but you can override the javascript anyway.
http://getbootstrap.com/javascript/#collapse-options
I couldn't get this to work either - this may be something in the Bootstrap JS related to the fact that you are using lists rather than divs?
So to get it to work, I had to override the click event. Based on this question here: Collapsible accordion doesn't work inside a dropdpwn-menu Bootstrap
I added an accordion-toggle class to each option link, and then added the following JavaScript to get it to work:
$(document).on('click', '.accordion-toggle', function(event) {
event.stopPropagation();
var $this = $(this);
var parent = $this.data('parent');
var actives = parent && $(parent).find('.collapse.in');
// From bootstrap itself
if (actives && actives.length) {
hasData = actives.data('collapse');
//if (hasData && hasData.transitioning) return;
actives.collapse('hide');
}
var target = $this.attr('data-target') || (href = $this.attr('href')) && href.replace(/.*(?=#[^\s]+$)/, ''); //strip for ie7
$(target).collapse('toggle');
});​
This fiddle shows it in action.
've been struggling with bootstrap collapse as well. I was trying to something do something slightly different. I wanted inline toggle behavior. See my JS fiddle below. What I found is that bootstrap seems to require the existence of the "accordion-group" div in addition to the data-parent attribute covered in their docs. So either there is a bug in the JS or their docs do not include it. I also had to zero out the styles on the accordion-group div...
http://jsfiddle.net/cssguru/SRFFJ/
<div id="accordion2">
<div class="accordion-group" style="border:0;padding:0;margin:0">
<div id="collapseOne" class="collapse in">
Foo Bar...
<a data-toggle="collapse" data-parent="#accordion2" href="#collapseTwo">
Show Herp Derp
</a>
</div>
<div id="collapseTwo" class="collapse">
Herp Derp...
<a data-toggle="collapse" data-parent="#accordion2" href="#collapseOne">
Show Foo Bar
</a>
</div>
</div>
</div>
You have to use accordion-group class in your items, see issue https://github.com/twitter/bootstrap/issues/4988