I'm trying to stay on a specif tab ( in this case tab2 ) but after clicking the submit button the tab reverts to tab 1 which has the default class of active. I have hit a brick wall with this one.
Here is my example [jsfiddle]:
HTML:
<ul class='tabs'>
<li><a href='#tab1'>Tab 1</a></li>
<li><a href='#tab2'>Tab 2</a></li>
</ul>
<div id='tab1'>
<h3>Section 1</h3>
<p>Lorem ipsum dolor sit amet, consssectetur adipiscing elit. Donec lobortis placerat dolor id aliquet. Sed a orci in justo blandit commodo. Vestibulum ante ipsum primis in faucibus orci luctus et ultrices posuere cubilia Curae.</p>
<form id="form1" action="" method="post">
<input id="button-1" name="" type="submit" />
</form>
</div>
<div id='tab2'>
<a name="tab2"></a>
<h3>Section 2</h3>
<p>Aenean et est tortor. In pharetra pretium convallis. Mauris sollicitudin ligula non mi hendrerit varius. Fusce convallis hendrerit mauris, eu accumsan nisl aliquam eu.</p>
<form id="form2" action="" method="post">
<input id="button-2" name="" type="submit" />
</form>
</div>
<div>
<h2>RESULTS </h2>
</div>
JavaScript:
$(document).ready(function(){
$('ul.tabs').each(function(){
var $active, $content, $links = $(this).find('a');
$active = $links.first().addClass('active');
$content = $($active.attr('href'));
$links.not(':first').each(function () {
$($(this).attr('href')).hide();
});
$(this).on('click', 'a', function(e){
$active.removeClass('active');
$content.hide();
$active = $(this);
$content = $($(this).attr('href'));
$active.addClass('active');
$content.show();
e.preventDefault();
});
});
});
CSS:
* {padding:0; margin:0;}
html {padding:15px 15px 0;font-family:sans-serif;font-size:14px;}
p, h3 {margin-bottom:15px;}
div {padding:10px;width:600px;background:#fff;}
ul.tabs {margin-left:2px;}
#tab1, #tab2 {border-top: solid 1px #ccc;margin-top: -1px; }
#tab2 {display:none;}a
ul.tabs li {list-style:none;display:inline;}
ul.tabs li a {padding:5px 10px;display:inline-block;background:#666;color:#fff;text-decoration:none;}
ul.tabs li a.active {background:#fff;color:#000;border: solid 1px #ccc; border-width: 1px 1px 0 1px;}
Your help would be greatly appreciated
click(function () { // bind click event to link $tabs. tabs('select', 4); // switch to tab return false; });
With the help of HTML, CSS, and JavaScript, it is possible to create a navigation menu with a curved active tab. This can be done by using the ::before and ::after pseudo-elements to create the desired shape, and then using JavaScript to add the active class to the element.
Try this
<asp:HiddenField ID="hidAccordionIndex" runat="server" Value="0" />
Put this in your coding and change the script as follows
$("#accordion").accordion({
header: "h3",
autoHeight: false,
event: "mousedown",
active: activeIndex,
ui: "PageName.aspx",
change: function (event, ui) {
var index = $(this).accordion("option", "active");
$('#<% =hidAccordionIndex.ClientID %>').val(index);
}
});
<div id="tab">
<ul>
<li><a href='#tab1'>Tab 1</a></li>
<li><a href='#tab2'>Tab 2</a></li>
</ul>
</div>
<form id="form1" action="?tab=tab1" method="post">
The jQuery function:
$(document).ready(function(){
$("#tab").tabs();
var param = $(document).getUrlParam('tab');
if (param !=null)
$("#tab").tabs('select',param);
else
$("#tab").tabs();
});
You can specify tab in URL. A tab is an anchor in a URL like: yourURL/#tab
<form id="form2" action="#tab2" method="post">
</form>
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With