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

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.

Related

How do I load the html pages on a div when I click in a link (using AJAX AND JQUERY)

<div id="menu">
<nav>
<ul class="nav_links">
<li><a id ="homelink" href="#">Home</a></li>
<li><a id="aboutlink" href="#">About</a></li>
<li><a id="locationlink" href="#">Location</a></li>
</ul>
</nav>
</div>
<Main id="main_container">
</Main>
Now I need the AJAX AND JQUERY code that when I click on one of the anchors, the content froM a document. HTML is displayed on main_container.
FOR EXAMPLE: CLICK ON HOME LINK>DISPLAY ON MAIN CONTAINER THE CONTENT FROM HOME
You need to use the jQuery .load() method to load the page URL, and event.preventDefault to prevent redirecting to the page itself, like so:
$('#menu .nav_links a').click(function(e) {
e.preventDefault();
var $this = $(this),
$href = $this.attr('href');
$('#main_container').load($href);
});

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>

How to search hyper link tag based on key pressed

<div>
<ul>
<li>1. View Profile</li>
<li>2. Change Password</li>
<li>3. Sign Out</li>
</ul>
</div>
As shown in above code, I want top open particular hyper link based on number pressed
ex- if I press '1' then hyper link should go to 'viewprofile.jsp'
if I press '2' then hyper link should go to 'chngpass.jsp'
In this way I want to perform, how to do it.
Sample example with JQuery:
$(function() {
var lnks = $('a').map(function() {
return this.href; //<-- fetch all hrefs in array
}).get();
$(document).on('keypress', function(e) { //<-- detect key press
var i = e.which - 49; //<-- ascii value of 1 is 49
if (lnks[i]) //<-- got link
window.location.href = lnks[i]; //<-- load page
});
});
<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script>
<div>
<ul>
<li>1. geeksforgeeks
</li>
<li>2. w3schools
</li>
<li>3. javatutorials
</li>
</ul>
</div>

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.