0

When I enter pin code and click on enter button it is not working though its working on mouse click. How to solve it?

<div class="input-box">
    <div class="z-btn">
        <label>Zip Code : </label><input type="text" id="cod" class="product-custom-option" name="cod" value="" placeholder="Enter pincode">
        <button type="button" onclick="checkCOD();" name="zip-check" title="Check" class="button" id="zip-check"><span>Check</span></button>
    </div>
    <div id="cod_msg"></div>
</div>

My Script as follows :

<script>
    function checkCOD(){
        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);
                },
                onFailure: function() { alert('Something went wrong...'); }
            });
        }
    }
</script>
3
  • please share the code or the extension name you used. Without code we cant help you Jul 11 '17 at 10:15
  • you can share it here. Just edit the questiion with the code Jul 11 '17 at 10:27
  • @RiddhishBhayani, check my edit in question
    – user51829
    Jul 11 '17 at 11:31
0

You can do this by adding a small Js function keypress event, Since you haven't posted your code, I show you an example:

Replace :

<script>
    function checkCOD(){
        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);
                },
                onFailure: function() { alert('Something went wrong...'); }
            });
        }
    }
</script>

with :

<script type="text/javascript">
    function checkCOD(){
            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);
                    },
                    onFailure: function() { alert('Something went wrong...'); }
                });
            }
    }
    //the add
    jQuery('document').ready(function(){
        jQuery('#cod').keypress(function(e){
                if(e.which == 13){//The Enter key pressed
                    jQuery('#zip-check').click();
                }
         });
    });
</script>
30
  • It's a very simple code, go to your page where you have this pin code product view i imagine ? so you find it in: app/design/frontend/yourpackage/yourtheme/template/catalog/product/view.phtml then check the id of the input text (the pin code) than replace #pin_code in js code with the other id
    – PЯINCƎ
    Jul 11 '17 at 11:10
  • look now please
    – PЯINCƎ
    Jul 11 '17 at 11:42
  • Not working plz check once again
    – user51829
    Jul 11 '17 at 11:48
  • 1
    Its should work, i tested it and it works ! look again your code, dont forget to clear you browser and Magento cache !
    – PЯINCƎ
    Jul 11 '17 at 11:59
  • I remove all caches Not working plz check once again
    – user51829
    Jul 11 '17 at 12:15

Your Answer

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