开发者

show/hide div section based on where the page is redirected from?

I have two php files which redirect like this

`header('Location: usrsecuredpage.php?div=subscription');`
`header('Location: usrsecuredpage.php?div=stusearch');`

On the "usrsecuredpage.php" I have a few javascrip toggle links on page which show and hide div sections. this is the code:

<li><a href="javascript:toggle('subscription')"><b>Subscription Details</b></a></li>
<li><a href="javascript:toggle('stusearch')"><b>Personal Information</b></a></li>

clicking the subscription toggle link shows subscription detail and hides personal information and vise versa..

I would like the headers being supplied by php pages to automatically show relev开发者_如何转开发ant div section. for example when header header('Location: usrsecuredpage.php?div=subscription'); is received from php page i would like subscription detail section to toggle and show up..

how can i do this?


Add a query string parameter to your URL and have the page show or hide the div based on the query string parameter.

For example,

header('Location: usrsecuredpage.php?ShowDiv=true');

Then, in the resulting page, you can check the value of that variable by using the global variable $_GET, like this:

$_GET['ShowDiv']

Using this variable, you can show or hide the div accordingly. Let me know if I can provide any more detail...


I would recommend using jquery for this if you can ... Just include the jquery library and then use this code ...

$("#yourDiv").show();


Use GET parameters that you can pass through the URL. For example, in your PHP file which redirects back to the original page, type the following for your redirection code:

header('Location: usrsecuredpage.php?div=sub'); // div='sub' or div='stu'

Now, in the usrsecuredpage.php file, include the following code near the top to find out which div to have open at the start:

$openDiv = $_GET['div'];

At this point the $openDiv variable will contain either 'sub', 'stu', or will not be defined (if you didn't include the parameter in the URL). You can use isset($openDiv) to find out whether it is defined or not. If it is defined, then compare against the value of $openDiv to find out which div to have open at the start. For example:

// initialize display of both divs to none
$subscriptionVisibility = "none";
$stusearchVisibility = "none";

// now, based on value of $openDiv, set above vars
if (isset($openDiv) && strcomp($openDiv,"sub") == 0)
   $subscriptionVisibility = "inline";
else if (isset($openDiv))
   $stusearchVisibility = "inline";

.
.
.

// now, whenever you create the divs, use their visibilities
echo "<div class='jotform-form' id='subscriptionDiv' style='display:$subscriptionVisibility;'></div>";
echo "<div class='jotform-form' id='stusearchDiv' style='display:$stusearchVisibility;'></div>";

In this example if your parameter was anything other than 'sub', the code assumes it was 'stu'. So if your parameter was 'bla', it would still make the stusearch div visible.

This may not be the best code for this solution, however, it should be enough to push you in the right direction. The overall approach is: pass the parameter in the URL string as a GET parameter (as I have shown), and then, in the usrsecuredpage.php file, use that parameter to determine which div should be open from the start.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜