Tab switcher

PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!

Moderator: General Moderators

Post Reply
ursl40
Forum Commoner
Posts: 37
Joined: Thu Nov 18, 2010 5:01 am

Tab switcher

Post by ursl40 »

Hy!

I have a tab switcher, with four different tabs, two of them are for user and car.

When I click (in my list of users) on selected user, it goes from there to tab swither - to tab user (for editting user). If I select tab car, car of that user comes up, and I can edit car (for editing car). But if I click button Save, it throws me back to tab user (all fields are empty) and if I after that again click on tab car, it says: Saved successfully...

Where is the problem? Thanks!
User avatar
superdezign
DevNet Master
Posts: 4135
Joined: Sat Jan 20, 2007 11:06 pm

Re: Tab switcher

Post by superdezign »

Vague, but if it says "saved successfully," it's likely been saved successfully. You just have an issue in your code where the default tab is still set to your "user" tab after submitting your form. If your "tab switcher" uses a hash on your URL to define the currently opened tab, then you need to use that in your <form>'s action attribute. So, if to default to the car tab you go to http://example.com/file.php#car, then change your action from "http://example.com/file.php" to "http://example.com/file.php#car".
ursl40
Forum Commoner
Posts: 37
Joined: Thu Nov 18, 2010 5:01 am

Re: Tab switcher

Post by ursl40 »

I don't know where the default tab is selected/written... I'm using this:
http://homework.nwsnet.de/products/e877_tab-switcher
ursl40
Forum Commoner
Posts: 37
Joined: Thu Nov 18, 2010 5:01 am

Re: Tab switcher

Post by ursl40 »

Anyone please?
User avatar
McInfo
DevNet Resident
Posts: 1532
Joined: Wed Apr 01, 2009 1:31 pm

Re: Tab switcher

Post by McInfo »

In tabswitcher.js, find

Code: Select all

    // Display the first tab content.
    this.show(this.targetIds[0]);
and replace it with

Code: Select all

    // Get the hash from the URI.
    var id = window.location.hash.split('#')[1];
    if (id) {
        // Display the requested tab content (if it exists).
        this.show(id);
    } else {
        // Display the first tab content.
        this.show(this.targetIds[0]);
    }
This solution could cause all tab pages to disappear if the hash does not match an existing tab id. You might want to test that the requested id matches one of the elements in the aElems array rather than just testing that the hash exists as is done here.

Be sure to follow superdezign's advice of adding the appropriate hash to the form's action attribute.
User avatar
superdezign
DevNet Master
Posts: 4135
Joined: Sat Jan 20, 2007 11:06 pm

Re: Tab switcher

Post by superdezign »

If McInfo's solution does cause issues, then find out how your tab switchers defines the active tab and submit the form with a query string in the action attribute instead of a hash. Then, use that to dynamically generate JavaScript code to define the active element.
Post Reply