Archive | September, 2010

JQUERY TAB SWITCHING ACCORDING TO QUERY STRING VALUE

28 Sep

As we all know about jquery tabs and tab switching.Here i would like to share the code for  jquery tab switching according to some query string values. 

 

Let “tabid” be the query string . The function getQuerystring() is used to get the value of the query string “tabid”.According to that value we can switch the jquery tabs using

$(‘#tabs’).tabs(‘select‘, inx)  Where inx is the query string value

The code is :

<script type=”text/javascript“>
$(document).ready(function() {
var inx = getQuerystring(“tabid“);
if (isNaN(inx))
inx = 2;
$(‘#tabs‘).tabs();
$(‘#tabs’).tabs(‘select‘, inx); 

});

function getQuerystring(key, default_) {
if (default_ == null) default_ = “”;
key = key.replace(/[\[]/, “\\\[“).replace(/[\]]/, “\\\]”);
var regex = new RegExp(“[\\?&]” + key + “=([^&#]*)”);
var qs = regex.exec(window.location.href);
if (qs == null)
return default_;
else
return qs[1];
}
</script>

Advertisements