Zen_j1 Posted December 31, 2015 Share Posted December 31, 2015 I have used a javascript i found on Internet in in address.tpl on ps 1.5 to validate the postcode entered by customer while add the address. This stop customer adding address where I donot deliver. But same javascript does not work on ps 1.6.1.3. can some help me to figure out what I am missing I have written the code <form name = "myform" form action="{$link->getPageLink('address', true)|escape:'html'}" method="post" class="std" id="add_address"> Preststashop 1.5 address.tpl code code code </form> /** I have added the javascript after </form> **/ <script type = "text/javascript">{literal}function checkZip() {var z = document.myform.postcode;var zv = z.value;if (!/^\d{6}$/.test(zv)) {alert ("Please enter a valid Pin Code");document.myform.postcode.value = "";myfield = z; // note myfield must be a global variablesetTimeout('myfield.focus(); myfield.select();' , 10); // to fix bug in Firefoxreturn false;}var codes = [111111,222222,333333,444444]; // add as many zip codes as you like, separated by commas (no comma at the end)var found = false;for (var i=0; i<codes.length; i++) {if (zv == codes) {found = true;break;}}if (!found) {alert ("Sorry, As if now we do not deliver at this Pin Code " + zv + " . We look forward for your business in near future.");document.myform.postcode.value = "";return false;}}{/literal}</script> In ps 1.6.3.1 line 42 <form name = "myform" form action="{$link->getPageLink('address', true)|escape:'html':'UTF-8'}" method="post" class="std" id="add_address"> Preststashop 1.6.31 address.tpl code code code </form> Here added same javascript code as above and it does not validate and create a error pop up as in case of ps 1.5 Link to comment Share on other sites More sharing options...
im_presto Posted December 31, 2015 Share Posted December 31, 2015 (edited) If you can share your website url, then i can figure it out. Also, on what event you are calling checkZip function ? Edited December 31, 2015 by im_presto (see edit history) Link to comment Share on other sites More sharing options...
Zen_j1 Posted December 31, 2015 Author Share Posted December 31, 2015 thanks for your reply Ps 1.5 I pasted the code as it is and validation occurs as soon mouse/cursor moves to another filed. for ps 1.6.1.3 I am working on localhost Link to comment Share on other sites More sharing options...
im_presto Posted December 31, 2015 Share Posted December 31, 2015 (edited) Ok, you need to add this code onblur="javascript:checkZip();" in line 103 and 151 in file address.tpl example: <input onblur="javascript:checkZip();" class="is_required validate form-control" data-validate="{$address_validation.postcode.validate}" type="text" id="postcode" name="postcode" value="{if isset($smarty.post.postcode)}{$smarty.post.postcode}{else}{if isset($address->postcode)}{$address->postcode|escape:'html':'UTF-8'}{/if}{/if}" /> Edited December 31, 2015 by im_presto (see edit history) 1 Link to comment Share on other sites More sharing options...
Zen_j1 Posted December 31, 2015 Author Share Posted December 31, 2015 Fantastic.It works. I like make a request to you for I more thing. As if now validation message/Error message is displayed as pop. There might chance a pop can be blocked by browser. I have seen some site display validation message/Error message just below or next to field in red how can this be done in this case. Link to comment Share on other sites More sharing options...
im_presto Posted December 31, 2015 Share Posted December 31, 2015 easily, you can inject error message text in html using javascript inner html, ie. document.getElementById('html-element-id').innerHTML = 'Error message'; Link to comment Share on other sites More sharing options...
Zen_j1 Posted December 31, 2015 Author Share Posted December 31, 2015 I am sorry but where do I write this code in above javascript which I posted or In address.tpl and how can I show it in red. Link to comment Share on other sites More sharing options...
im_presto Posted December 31, 2015 Share Posted December 31, 2015 send me pm and attach your address.tpl, i will write you the code. Link to comment Share on other sites More sharing options...
Zen_j1 Posted January 1, 2016 Author Share Posted January 1, 2016 I have sent a pm did not find a option attach a file so just copied and pasted entire code in message please highlight the added code. Link to comment Share on other sites More sharing options...
Recommended Posts
Create an account or sign in to comment
You need to be a member in order to leave a comment
Create an account
Sign up for a new account in our community. It's easy!
Register a new accountSign in
Already have an account? Sign in here.
Sign In Now