homepage Welcome to WebmasterWorld Guest from 54.167.173.250
register, free tools, login, search, pro membership, help, library, announcements, recent posts, open posts,
Become a Pro Member

Visit PubCon.com
Home / Forums Index / Code, Content, and Presentation / JavaScript and AJAX
Forum Library, Charter, Moderator: open

JavaScript and AJAX Forum

    
Help with hiding a div
adammc




msg:4518280
 11:15 am on Nov 12, 2012 (gmt 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;
}
}
//-->
</script>


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

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

--></style>




------ 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">



<tr>
<td align="left" class="text"><span class="brown3">Card Type :</span> </td>
<td align="left"><select name="cctype" class="username">
<option value=""></option>
%%CCTYPES%%
</select>
%%CCTYPEREQUIRED%%
</td>
</tr>
<tr>
<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">
%%CCNUMBERREQUIRED%%</td>
</tr>
<tr>
<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>
%%CCMONTHS%%
</select>

<select name="ccyear" class="username">
<option value="">Select Year</option>
%%CCYEARS%%
</select>
%%CCEXPIREREQUIRED%%
</tr>
<tr>
<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">
%%CVVREQUIRED%%</td>
</tr>
<!-- END CREDITCARD -->


</td></tr></table>

 

adammc




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

can anyone possibly help?

Fotiman




msg:4519046
 3:25 pm on Nov 14, 2012 (gmt 0)

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(){};

Global Options:
 top home search open messages active posts  
 

Home / Forums Index / Code, Content, and Presentation / JavaScript and AJAX
rss feed

All trademarks and copyrights held by respective owners. Member comments are owned by the poster.
Home ¦ Free Tools ¦ Terms of Service ¦ Privacy Policy ¦ Report Problem ¦ About ¦ Library ¦ Newsletter
WebmasterWorld is a Developer Shed Community owned by Jim Boykin.
© Webmaster World 1996-2014 all rights reserved