0

I am building an ecommerce magento site named www.bookslab.in. I had one issue in this website. I want to make compulsory for every user to check their zipcode before they buy anything from the website, because i am delivering the products in the limited area. Now i had added the exception for that. The exception is when user's zipcode is invalid then ADD_TO_CART button is disabled, this is the exception. So, the problem comes here when user checks that the zipcode he enters is wrong, so after that he enters the correct zipcode, but still the ADD_TO_CART button is disabled. To solved this issue, i want to refresh(reload) the page everytime when user clicks on CHECK button of zipcode field. Plz suggest me in the code i provided & go to my website to see the problem.

cod.phtml

<?php
/***************************************
 *** Cash On Delivery ***
 **************************************
 */

$msgData = Mage::helper('netgo_cod')->getConfigData(); 
if($msgData['zip_status'] == 1){
?>
<div class="input-box">
    <div class="z-btn">
        <label>Zip Code : </label><input type="text" placeholder="Enter your pincode" value="" name="cod" class="product-custom-option required-entry" id="cod" size="29" style='color:black; font-size:12px'>
        <button type="button" onclick="checkCOD();" name="zip-check" title="Check" class="button" id="zip-check"><span><span>Check</span></span></button>
    </div>
    <div id="cod_msg"></div>
</div>

<script>
    function checkCOD(){
             var zipcode;
        var cod = $('cod').value;
        if(cod == ''){
            $('cod_msg').update('<span class="cod-error"><?php echo $msgData['emp_msg']; ?></span>');
            return
        }else{
            $('cod_msg').update('<img src="<?php echo Mage::getBaseUrl( Mage_Core_Model_Store::URL_TYPE_WEB, true ).'media/cod/img/ajax-loader-2.gif';?>">'); 
            new Ajax.Request('<?php echo Mage::getBaseUrl().'netgo/cod/check';?>', {
                method:'post',
                parameters: {zipcode: cod}, 
                onSuccess: function(transport) {
                    var response = transport.responseText || "no response text";
                    $('cod_msg').update(response);

                    if(response.search('Delivery of the book is not available on the above pincode')!=-1)
                                        {
                                          zipcode='checked';
                                          jQuery('.btn-cart').attr('disabled', 'disabled'); 
                                        }
                                      else
                                      {
                                      zipcode='';

                                      }

                },
                onFailure: function() { alert('Something went wrong...'); }
            });
        }
    }
</script>
<?php } ?>

Screenshot:

enter image description here

0

Please try after replacing your script code with the following code. You don't need to refresh the page to enable the button.

<script>
    function checkCOD(){
             var zipcode;
        var cod = $('cod').value;
        if(cod == ''){
            $('cod_msg').update('<span class="cod-error"><?php echo $msgData['emp_msg']; ?></span>');
            return
        }else{
            $('cod_msg').update('<img src="<?php echo Mage::getBaseUrl( Mage_Core_Model_Store::URL_TYPE_WEB, true ).'media/cod/img/ajax-loader-2.gif';?>">'); 
            new Ajax.Request('<?php echo Mage::getBaseUrl().'netgo/cod/check';?>', {
                method:'post',
                parameters: {zipcode: cod}, 
                onSuccess: function(transport) {
                    var response = transport.responseText || "no response text";
                    $('cod_msg').update(response);

                    if(response.search('Delivery of the book is not available on the above pincode')!=-1)
                                        {
                                          zipcode='checked';
                                          jQuery('.btn-cart').attr('disabled', 'disabled'); 
                                        }
                                      else
                                      {
                                       jQuery('.btn-cart').removeAttr('disabled');

                                      }

                },
                onFailure: function() { alert('Something went wrong...'); }
            });
        }
    }
</script>

Now when the user will enter the correct code, the add to cart button will automatically get enabled without refreshing the page.

| improve this answer | |
  • Knowband i need to refresh the page to make the add_to_cart button enabled after it getting disabled if user enter does not enter the correct zipcode. did you get now! – Salman Dalal Nov 3 '16 at 16:04
  • I want add to cart button enabled only when zipcode is valid otherwise it should be disabled if zipcode is wrong – Salman Dalal Nov 3 '16 at 16:06
  • Any answer to this – Salman Dalal Nov 4 '16 at 7:51
  • any answer stackys! – Salman Dalal Nov 4 '16 at 15:42
  • Any answer guys – Salman Dalal Nov 5 '16 at 6:42

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.