Hello,
I have a form with a tab panel control
Tab container name (client id) : Tabs
I would like to know how to set and prevent the tab from moving from index 0 if the request.querystring("pid") is empty or null.
Here is my current javascript:
<scripttype="text/javascript">function PanelClick(sender, e) {var mpid = gup('pid');
if (mpid=="") {
SetActiveTab("Tabs",0);
}
}
function ActiveTabChanged(sender, e) {var mpid = gup('pid');if (mpid=="") {
alert("Please choose a page or create a new page first");
returnfalse;}
}
function SetActiveTab(tabControl, tabNumber){
var ctrl = $find(tabControl);ctrl.set_activeTab(ctrl.get_tabs()[tabNumber]);
}
function gup( name ){name = name.replace(/[\[]/,"\\\[").replace(/[\]]/,"\\\]");
var regexS ="[\\?&]"+name+"=([^]*)";
var regex =new RegExp( regexS );var results = regex.exec( window.location.href );
if( results ==null )return"";else
return results[1];}</script>
I guess all I need is the javascript reference to the active tab...
can anyone help me with this?
Ok, through a little more research, I found out how to navigate or prevent navigation of the tabs control via javascript:
Here's the code
<scripttype="text/javascript">
/
function ActiveTabChanged(sender, e) {var mpid = gup('pid'); // get the querystring in the url by calling the gup function below... good little snippet for querystrings in javascript.
var activeTab = $get("Tabs"); // gets the element by the id of "Tabs" and defines the control variable activeTab.activeTab.value = sender.get_activeTabIndex(); // gets the active tab index of the control.
if (mpid=="" && activeTab.value!=0) { // if the conditions aren't right then don't allow the user to navigate to any other tab.
alert("Please choose a page or create a new page first"); // alert the user.
SetActiveTab("Tabs",0); // sets the active tabreturnfalse; // doesn't allow the process to go to another tab.
}
}
function SetActiveTab(tabControl, tabNumber){
var ctrl = $find(tabControl);ctrl.set_activeTab(ctrl.get_tabs()[tabNumber]);
}
function gup( name ){name = name.replace(/[\[]/,"\\\[").replace(/[\]]/,"\\\]");
var regexS ="[\\?&]"+name+"=([^]*)";
var regex =new RegExp( regexS );var results = regex.exec( window.location.href );
if( results ==null )return"";else
return results[1];}</script>
I hope that the scripts above can help someone else.
No comments:
Post a Comment