SitePoint Sponsor

User Tag List

Results 1 to 2 of 2
  1. #1
    SitePoint Guru adammc's Avatar
    Join Date
    Aug 2004
    Cairns, Australia
    0 Post(s)
    0 Thread(s)

    Help with hiding a div

    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">
    			<!-- END CREDITCARD -->

  2. #2
    SitePoint Enthusiast
    Join Date
    Oct 2010
    0 Post(s)
    0 Thread(s)
    Try to force the cache to reload on this page for this script every time the page is loaded.


Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts