1

please visit this link :

http://kidsdial.com/soft-buddies-lying-love-dog-s-white-10-inch-3621.html

type any zip code and type "enter" using keyboard.

than its rediecting to checkout page.

I want to avoid that redirection ,

file for checking zip code = http://pastebin.com/jpXfM3Be

view.phtml = http://pastebin.com/GuWAYxbz

please help me to find solution

2

You just need to replace line

<input type="text" placeholder="Enter your PIN Code" class="input-text" maxlength="120" id="zipcode" size="20" name="zipcode">

With

<input type="text" placeholder="Enter your PIN Code" class="input-text" maxlength="120" id="zipcode" size="20" name="zipcode" onkeydown="if (event.keyCode == 13) { return false;}">

Or

<input type="text" placeholder="Enter your PIN Code" class="input-text" maxlength="120" id="zipcode" size="20" name="zipcode" onkeypress="if (event.keyCode == 13) { return false;}">

<script>
    document.getElementById('zipcode').onkeypress = function(e){
        if (!e) e = window.event;
        var keyCode = e.keyCode || e.which;
        if (keyCode == '13'){
          // Do your ajax process which you are doing on zip-check click button same way.

              new Ajax.Request("<?php echo $this->getUrl('checkdelivery/index/index') ?>", {
                    method: "get",
                    parameters: {zipcode : $('zipcode').value },
                    onSuccess: function(transport) {
                             var json = transport.responseText.evalJSON();
                             $('delivery-message').update(json.message);                             
                             $('delivery-message').setStyle({ color: json.color});
                             $('delivery-html').update(json.html); 
                    }
            });

          return false;
        }
      }
</script>
  • 1
    edited my answer for showing error or success message same way when you click on check button. – Akhilesh Patel Oct 2 '15 at 17:02
  • 1
    You need to wrap the ajax request in a separate function. Then execute the function if either the enter key is pressed or the button is clicked. – Milan Simek Oct 2 '15 at 17:09
  • 1
    Let's wait for @Akhilesh Patel to update the code, I don't want to 'steal' his answer. – Milan Simek Oct 2 '15 at 17:12
  • 1
    Edited my answer. I added your ajax code in my javascript. If that still not work try to remove onkeydown="if (event.keyCode == 13) { return false;}" from that text field. – Akhilesh Patel Oct 2 '15 at 17:14
  • 1
    Let me know if that work for you. – Akhilesh Patel Oct 2 '15 at 17:16

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.