I have created a jquery ui tab and what I would like to do is when the page containing the jquery ui tab loads, specific tab will open depends on the previous page. So far, I have down the following:
PHP:
- obtain the previous page by using $_SERVER['HTTP_REFERER'];
- determine which tab to open by using a "if" statement (assigning a tab_index variable);
- assign "tab_index" to a hidden input value.
Javascript:
- pick up the hidden input value and assign it to a js variable;
- ??
Then I am not too sure how to do this make it work in $('#tabs').tabs({.... statement. Any idea of how to resolve this will be much appreciated. Many thanks.
PHP:
$string = $_SERVER['HTTP_REFERER'];
$string = substr($string, -(strlen($string)-strrpos($string, '/')-1), strlen($string)-strrpos($string, '/'));
if ($string == "specific_page.php") {
$tab_index = 2;
} else {
$tab_index = 0;
}
HTML:
...
<input id="hidden_input" type="hidden" value="<?php echo $tab_index; ?>" />
JS:
$(document).ready(function() {
var tab_index = $('#hidden_input').attr('value')
$('#tabs').tabs({ cache:false,
ajaxOptions: {
error: function(xhr, status, index, anchor) {
$(anchor.hash).html("Couldn't load this tab. We'll try to fix this as soon as possible.");
}
},
...something here for tab selection?...
});
});