Welcome to WebmasterWorld Guest from

Forum Moderators: open

Message Too Old, No Replies

Help with hiding a div

11:15 am on Nov 12, 2012 (gmt 0)

Preferred Member

10+ Year Member

joined:Sept 1, 2004
posts: 389
votes: 0

Hi folks,

I have a javascript / css code on my cart page to hide/show the credit card info to the user (using a dropdown box).
The problem is that if a user submits the form after choosing 'credit card / nab' and leaves the page.... If they use their back button or go back to the cart the payment type is already selected and cannot be changed to another option!

How can I fix this?

-------Header -----------

<script type="text/javascript"><!--
var lastDiv = "";
function showDiv(divName) {
// hide last div
if (lastDiv) {
document.getElementById(lastDiv).className = "hiddenDiv";
//if value of the box is not nothing and an object with that name exists, then change the class
if (divName && document.getElementById(divName)) {
document.getElementById(divName).className = "visibleDiv";
lastDiv = divName;

<style type="text/css" media="screen"><!--

.hiddenDiv {
display: none;
.visibleDiv {
display: block;


------ Body --------

<option value="">Select a payment method</option>

<option value='nab' <?php if(isset($_SESSION['BILLING']['PAYMENTTYPE']) && $_SESSION['BILLING']['PAYMENTTYPE'] == 'nab'){echo ' selected="selected" ';} ?>>Credit Card</option>
<option value='offline' <?php if(isset($_SESSION['BILLING']['PAYMENTTYPE']) && $_SESSION['BILLING']['PAYMENTTYPE'] == 'offline'){echo ' selected="selected" ';} ?>>Direct Deposit</option>

<option value='paypal' <?php if(isset($_SESSION['BILLING']['PAYMENTTYPE']) && $_SESSION['BILLING']['PAYMENTTYPE'] == 'paypal'){echo ' selected="selected" ';} ?>>Paypal</option>

<table id="nab" class="hiddenDiv">

<td align="left" class="text"><span class="brown3">Card Type :</span> </td>
<td align="left"><select name="cctype" class="username">
<option value=""></option>
<td align="left" class="text"><span class="brown3">Credit Card Number :</span> </td>
<td align="left"><input type="text" name="ccnumber" size="24" value="%%CCNUMBER%%" class="username">
<td align="left" class="text"><span class="brown3">Expiration Date (mm/yyyy) : </span></td>
<td align="left"><select name="ccmonth" class="username">
<option value="">Select Month</option>

<select name="ccyear" class="username">
<option value="">Select Year</option>
<td align="left" class="text"><span class="brown3">CVV Code :</span> </td>
<td align="left"><input type="text" name="cvvcode" size="5" value="%%CVVCODE%%" class="username">

11:48 am on Nov 14, 2012 (gmt 0)

Preferred Member

10+ Year Member

joined:Sept 1, 2004
posts: 389
votes: 0

can anyone possibly help?
3:25 pm on Nov 14, 2012 (gmt 0)

Senior Member from US 

WebmasterWorld Senior Member fotiman is a WebmasterWorld Top Contributor of All Time 10+ Year Member Top Contributors Of The Month

joined:Oct 17, 2005
posts: 5019
votes: 24

1. Don't wrap script and style contents in HTML comments.
2. The problem is that the browser still has the previous page loaded in cache, so when you go back, it doesn't trigger any "load" events, it just returns to the last known state. To prevent this, you can define an onunload event handler, which will force the browser to release the cache. Note, only do this on the pages where caching is detrimental to the behavior.

window.onunload = function(){};