I have the following layout
<div id="tabs">
<ul>
<li>Create Username</li>
<li>View Search Logs</li>
<li>Assign Values Table</li>
<li>Edit Values Table</li>
<li>Create Values Table</li>
</ul>
<div id="tabs-1">
<h2>Create Username</h2>
</div>
<div id="tabs-2">
<h2>View Search Logs</h2>
</div>
<div id="tabs-3">
<h2>Assign Values Table</h2>
</div>
<div id="tabs-4">
<h2>Edit Values Table</h2>
</div>
<div id="tabs-5">
<h2>Create Values Table</h2>
</div>
</div>
Each tab has a form in it, when the form is submitted and the page reloads I want the visible tab to still be the tab the user was last on (instead of it going back to the first).
Each form has a hidden field that contains the index of that tab. I then use the below:
<script type="text/javascript">
$(function() {
$("#tabs").tabs({
selected: <?php echo (isset($_POST['selected_tab']) ? $_POST['selected_tab'] : 1)?>
});
});
</script>
This results in showing the right thing e.g
<script type="text/javascript">
$(function() {
$("#tabs").tabs({
selected: 2
});
});
</script>
However the first tab is still the tab that is shown.
$("#tabs").tabs({
selected: 2
});
Should be:
$("#tabs").tabs({
active: 2
});
Tabs uses active property and not selected property.
Also note that the index is base 0, so if you want to select the 2nd tab, your value needs to be 1.
One option would be to include jquery-cookie.js an use tabs like this:
$( "#tabs" ).tabs({
cookie: {
expires: 1
}
});
And this will automatically manage your last open tabs with cookie.
Related
So I am refactoring and redesigning an old application and I have multiple dropdown menus that hold data for people to enter and I would like for there to be a button that when clicked on scrolls to the next one and opens it just to make it easier to get through the form.
My html code looks like this:
<?php foreach loop that adds more dropdowns when entered in through a modal when they click new?>
<button class="tEntry-collapsible-btn tsHeader-collapsible-btn waves-effect"
id="testing"
type="button"
style="background-color: sienna !important;"></button>
<div class="tEntry-collapsible-row>
<div class="tTable-row">
//content to dropdown
</div>
</div>
....usually around 10-15 dropdown menus with the collapsible btn
<?php loop++ ?>
I added a photo for reference, the dropdown buttons are color coordinated and I added a next button at the bottom (minimal styling) and as of right now when the buttons are clicked it drops down fine but I'd also like a button that when clicked i guess focuses the next one and then opens it just for a smoother experience when working your way down the page.
Something like this?
Find the next dropdown and scroll to it with .scrollIntoView().
You would just call the function that drops the dropdown on the next element.
Note: not working well in the snippet... try my codepen
$(function() {
$(document).on('click', '.next', function() {
var el = $(this).closest('.dropdown');
var parent = el.closest('.wrap');
var next = el.nextAll('.dropdown').first();
// scroll like this
// parent.animate({
// scrollTop: next.position().top
// }, 1000);
// or like this; I prefer this one
next[0].scrollIntoView({ behavior: 'smooth', block: 'start' });
});
});
.wrap {
height: 200px;
overflow-y: scroll;
}
.something {
height: 50px;
}
<script src="https://cdnjs.cloudflare.com/ajax/libs/jquery/3.3.1/jquery.min.js"></script>
<div class="wrap">
<div class="dropdown">
<ul>
<li>item</li>
<li>item</li>
<li>item</li>
<li>item</li>
</ul>
<button class="next">next</button>
</div>
<div class="something"></div>
<div class="dropdown">
<ul>
<li>item</li>
<li>item</li>
<li>item</li>
<li>item</li>
</ul>
<button class="next">next</button>
</div>
</div>
I am writing an admin dashboard in PHP at the moment.
To simplify things, as far as I think it simplifies, the page I structured has the typical areas Header, Aside with menu and MainContent page. The main content page should change when I click a different page in the aside menu.
So I created the page index.php which will hold the whole framework of the page.
<?php include('../includes/overall/overallHeader.php'); ?>
<section class="content-header">
<h1>Einsatzliste</h1>
</section>
<script type="text/javascript">
$('#pageIncidents').click(function(){
$('#mainContent').load('incidents.php');
});
</script>
<section class="content">
<div id="mainContent">
</div>
</section>
<?php include('../includes/overall/overallFooter.php'); ?>
Within this I created the section content, and gave the div inside the id mainContent. My idea was to load different subpages into this div, when I click a menu item in the aside menu:
aside menu
<div class="navbar-default sidebar" role="navigation">
<div class="sidebar-nav navbar-collapse">
<ul class="nav in" id="side-menu">
<li><div id="pageIncidents">Einsatzliste</div></li>
<li>Testseite 1</li>
</ul>
</div>
</div>
There I put the link inside a div with a unique ID which I want to use in jQuery to load the specific contents.
jQuery script
<script type="text/javascript">
$('#pageIncidents').click(function(){
$('#mainContent').load('incidents.php');
});
</script>
The script is supposed to load the page incidents.php into the div mainContent in the index.php page.
It totally does not work... Do you have a hint where to look for? I think the logic seems right I guess. Could it be a problem, that the id "pageIncidents" is not directly visible in the code but included by the php include overallHeader at the top of the page?
You can try doing it with ajax and make up the ajax response in html (string), onclick start ajax request.
$(document).on("click", ".delete-asset", function() {
var link = $(this).attr('[data-page]');
$.ajax({
type:'GET',
url:'http://www.example.com/index.php',
dataType: "json",
data: {
action: 'incidents',
data: { 'incidents': 'incidents' }
},
success:function(data) {
$('#mainContent').html("[your data]");
}
});
});
In my code which is using bootstrap, I got a problem.
I am using JS code shown as below.
$( "li:eq(1)" ).click(function() {
$.get("./test.php")
.done(function(data) {
$('#middle').html(data);
});
It is to control the div.
<div class="container" id=header-nav>
<a class="brand" href="index.php"></a>
<div class="nav-collapse collapse" >
<ul class="nav">
<li class="active">Home</li>
<li>test</li>
.......
<div class="container" id="middle"> </div>
When I click the test button, the link will change to test.php# but nothing change. Click again, it can load into the test.php.
The problem is the link is test.php, the code not work. when test.php# , it work. And I would like to know why.
Thanks a lot.
The problem is because you have attached the handler to the li element, but the a element is clicked, and then transfers the page. Try this instead:
$("li:eq(1) a").click(function(e) {
e.preventDefault();
$.get("./test.php")
.done(function(data) {
$('#middle').html(data);
});
});
The preventDefault() stops the default behaviour of the link, meaning your AJAX request gets executed as required.
since you want to use $.get (AJAX), you don't have to give the url to <a> element inside your <li> element,
you have to give the attribute href inside <a> element this value: javascript:void(0) Or #,
your html code would be:
<div class="container" id=header-nav>
<a class="brand" href="index.php"></a>
<div class="nav-collapse collapse" >
<ul class="nav">
<li class="active">Home</li>
<li>test</li>
.......
<div class="container" id="middle"> </div>
or you have to prevent default action for the element to prevent reloading url by adding:
event.preventDefault() in you onclick event and your js code would be:
$( "li:eq(1)" ).click(function(e) {
event.preventDefault();
$.get("./test.php")
.done(function(data) {
$('#middle').html(data);
});
I'm quite sure this has never been asked before.
I am new to jQuery and found jqmPhp very easy to use. However, I am trying to achieve a few things that I find very complicated to implement.
I need to filter list items (like here) and enable the user to check/uncheck several list items to delete. I am trying to implement a similar feature to what Gmail mobile is doing (with a checkbox on the left, where selecting it will make the relevant row highlight and allows users to just click a button to delete checked rows).
Is it possible at all to do that with jqmphp? If so, can anyone assist me with more information, links or code?
I made a Demo for you, by converting list-view into check-able list items.
http://jsfiddle.net/Palestinian/vcXmK/
HTML
<div data-role="page">
<div data-role="header">
<h1>Header</h1>
</div>
<div data-role="content">
<ul id="list-view-test" data-role="listview" data-autodividers="true" data-filter="true" data-inset="true">
<li>Adam Kinkaid
</li>
<li>Alex Wickerham
</li>
<li>Avery Johnson
</li>
<li>Bob Cabot
</li>
<li>Caleb Booth
</li>
<li>Christopher Adams
</li>
<li>Culver James
</li>
</ul>
Delete
Reset
</div>
<div data-role="footer">
<h1>Footer</h1>
</div>
</div>
Code
// Change icons
$('#list-view-test').find('span.ui-icon').each(function () {
if ($(this).hasClass('ui-icon-arrow-r')) {
$(this).removeClass('ui-icon-arrow-r').addClass('ui-icon-checkbox-off');
}
$('#list-view-test').listview('refresh');
});
// toggle "checked/unchecked"
$('#list-view-test').on('click', 'li', function (event) {
event.preventDefault();
$(this).find('span.ui-icon').removeClass('ui-icon-checkbox-off').addClass('ui-icon-checkbox-on');
});
// Delete selected
$('#del').on('click', function () {
$('span.ui-icon').each(function () {
if ($(this).hasClass('ui-icon-checkbox-on')) {
$(this).closest('li').remove();
$('#list-view-test').listview('refresh');
}
});
});
// Clear selection
$('#reset').on('click', function () {
$('span.ui-icon').each(function () {
if ($(this).hasClass('ui-icon-checkbox-on')) {
$(this).removeClass('ui-icon-checkbox-on').addClass('ui-icon-checkbox-off');
}
});
});
I use a simple jquery code for tabs, the idea of it: in each tab I have a form when i submit each form the code will give me values from mysql . The problem is when i submit a form in for example tab 3 it will redirect me to the first tab (default tab), before I show any result.
any suggestion to solve this problem.
thanks in advance,
My Code :
<script type="text/javascript">
$(function() {
$( "#tabs" ).tabs();
});
</script>
HTML code :
<div id="tabs">
<ul>
<li>tab 1</li>
<li>tab 2</li>
<li>tab 3</li>
</ul>
<div id="tabs-1">
<p>tab 1 content</p>
</div>
<div id="tabs-2">
<p>tab 2 content</p>
</div>
<div id="tabs-3">
<p>tab 3 content</p>
</div>
</div>
If you use php, you could use for e.g. hidden html-field in form which contains number of the tab. When submitting form you could parse that variable and use it in jQuery-code. If you use php inside jQuery code could look like this:
$("#tabs").tabs({
selected: <?php echo (isset($_POST['selected_tab']) ? $_POST['selected_tab'] : 1)?>
});
You jest use this code
$( ".selector" ).tabs( "load", 2 );
after loading call this one so you can select 2 tab.
Try it!!
You can pass parameters to tabs() function (http://api.jqueryui.com/tabs/)
<script type="text/javascript">
$(function() {
$( "#tabs" ).tabs({active: 2});
});
</script>
you said "forms" if you submit the form, the page will send data and refresh itself. Just use a button and when the button is clicked, send the ajax.