milerwan Posted June 5, 2018 Author Share Posted June 5, 2018 17 hours ago, raiwa said: I don't know why it doesn't show the error. Maybe it's because the script is accessed via javascript? But if 'state_name' is not in the array listed, it is not set and doesn't exist. Meanwhile it's always better to echo variables where they are used: require('includes/application_top.php'); echo '$_POST' . print_r($_POST); $country_id = $_POST['country_id']; $state_name = $_POST['state_name']; $check_query = tep_db_query("select count(*) as total from zones where zone_country_id = '" . (int)$country_id . "'"); echo '$_POST' shows $_POST as text (I think you have made a mistake). echo $_POST shows Array Eventually, echo $_POST['state_name'] shows the variable selected result (13). print_r($_POST) shows the array : Array ( [country_id] => 21 [state_name] => 13 ) NB: print_r($_POST) don't need echo to be displayed. Frankly it's a lot of quibbles for not much ... If I write it this way it looks better for you ? : echo tep_draw_input_field('state', (isset($state_name) ? $state_name : ''), 'id="inputState" placeholder="' . ENTRY_STATE_TEXT . '"'); Quote Osc v2.3.4 BS "custom" PHP 7.3 compatible (710 modified files => o_O') Link to comment Share on other sites More sharing options...
♥raiwa Posted June 5, 2018 Share Posted June 5, 2018 I do the text echo to see where it is displayed even there is no variable content, it's just my habit. I would say correct is to apply the isset check where the ·POST variable is used: $state_name = (isset($_POST['state_name']) ? $_POST['state_name'] : ''); $state name is always defined in your code, no need to check it in the menu. Quote About Me: http://www.oscommerce.com/forums/user/249059-raiwa/ Need help? How To Get The Help You Need Is your version of osC up to date? You'll find the latest osC community version CE Phoenix here. Public Phoenix Change Log Cheat Set on Google Sheets Link to comment Share on other sites More sharing options...
Guest Posted June 12, 2018 Share Posted June 12, 2018 Quote 1. For those who has got 2.3.4.1 CE Frozen version and/or fontawesome 5 : Edit includes/modules/header_tags/ht_country_state_jquery.php file and find this code : I have no such file. I am using 2.3.4.1 CE Downloaded and installed on May 26th. Do I need to upgrade already? I've installed this contribution and I have no dropdown box for the state field at all. Only the country. Please advise! - Andrea Quote Link to comment Share on other sites More sharing options...
Guest Posted June 12, 2018 Share Posted June 12, 2018 Ignore my post. Been staring at the screen too long today. I'm good. - Andrea Quote Link to comment Share on other sites More sharing options...
Krisz1 Posted December 7, 2018 Share Posted December 7, 2018 This contribution was exactly was I was looking for. Thank you ! Quote Link to comment Share on other sites More sharing options...
kdenby Posted May 16, 2019 Share Posted May 16, 2019 Hello Milerwan - great little contribution .... almost solved my requirement out of the box .... but ... works fine in create_account.php but when I try to add a new address to an account ie using address_book_process.php the spinner runs but I get no states pull down, only an empty input box. Not sure where to start looking for the problem but I have installed a mint version of address_book_process.php and address_book_details.php from osCommerce 234 Bootstrap Master. Any ideas? Thanks Quote Link to comment Share on other sites More sharing options...
milerwan Posted May 21, 2019 Author Share Posted May 21, 2019 (edited) On 5/16/2019 at 12:19 PM, kdenby said: Hello Milerwan - great little contribution .... almost solved my requirement out of the box .... but ... works fine in create_account.php but when I try to add a new address to an account ie using address_book_process.php the spinner runs but I get no states pull down, only an empty input box. Not sure where to start looking for the problem but I have installed a mint version of address_book_process.php and address_book_details.php from osCommerce 234 Bootstrap Master. Any ideas? Thanks From "admin -> Modules -> Header Tags -> Country/States Selector", you have to edit the module and tick the missing page(s) to apply the script : address_book_process.php checkout_payment_address.php checkout_shipping_address.php create_account.php Edited May 21, 2019 by milerwan Quote Osc v2.3.4 BS "custom" PHP 7.3 compatible (710 modified files => o_O') Link to comment Share on other sites More sharing options...
kdenby Posted May 23, 2019 Share Posted May 23, 2019 Thanks for getting back to me ... but .. I had already made those selections in the module. The state selector pulldown appears fine in a new account - ie create_account.php but once an account is created then adding a new address or editing the already created one has no pulldown (though the spinner runs on program launch) - see screenshots below. Cheers Quote Link to comment Share on other sites More sharing options...
♥cannuck1964 Posted November 4, 2021 Share Posted November 4, 2021 I want to run this on every page load. I am using : $(document).ready(function(){ if($("#inputCountry").val()==""){ $("#inputCountry").val('223'); } if($("#inputCountry").val()!=""){ $("label[for='inputState']+div").html('<i class="fa fa-spinner fa-spin fa-2x fa-fw" style="margin-top:2px; margin-bottom:9px; margin-left:0px;"></i>'),id_country=$("#inputCountry").val(),$.post("states.php",{country_id:id_country,state_name:sn},function(a){ $("label[for='inputState']+div").html(a) } ) } }); The state does not change from USA to Canada. I have put the script below the drop downs in the code. Not sure why it is not though, is there a specific BS version I need to be using or some tool in the BS release? Quote Peter McGrath ----------------------------- See my Profile (click here) for more information and to contact me for professional osCommerce support that includes SEO development, custom development and security implementation Link to comment Share on other sites More sharing options...
♥cannuck1964 Posted November 4, 2021 Share Posted November 4, 2021 This is the form input I am using: <div class="md-form pb-3"> <div class="form-group has-feedback"> <label for="inputState" class="control-label col-sm-6">State/Province:</label> <select name="state" placeholder="Enter State" required aria-required="true" aria-describedby="atState" id="inputState" class="form-control validate white-text" > <option value="1">Alabama</option><option value="2">Alaska</option><option value="4">Arizona</option><option value="5">Arkansas</option><option value="12">California</option><option value="13">Colorado</option><option value="14">Connecticut</option><option value="15">Delaware</option><option value="16">District of Columbia</option><option value="18" selected="selected">Florida</option><option value="19">Georgia</option><option value="21">Hawaii</option><option value="22">Idaho</option><option value="23">Illinois</option><option value="24">Indiana</option><option value="25">Iowa</option><option value="26">Kansas</option><option value="27">Kentucky</option><option value="28">Louisiana</option><option value="29">Maine</option><option value="31">Maryland</option><option value="32">Massachusetts</option><option value="33">Michigan</option><option value="34">Minnesota</option><option value="35">Mississippi</option><option value="36">Missouri</option><option value="37">Montana</option><option value="38">Nebraska</option><option value="39">Nevada</option><option value="40">New Hampshire</option><option value="41">New Jersey</option><option value="42">New Mexico</option><option value="43">New York</option><option value="44">North Carolina</option><option value="45">North Dakota</option><option value="47">Ohio</option><option value="48">Oklahoma</option><option value="49">Oregon</option><option value="51">Pennsylvania</option><option value="53">Rhode Island</option><option value="54">South Carolina</option><option value="55">South Dakota</option><option value="56">Tennessee</option><option value="57">Texas</option><option value="58">Utah</option><option value="59">Vermont</option><option value="61">Virginia</option><option value="62">Washington</option><option value="63">West Virginia</option><option value="64">Wisconsin</option><option value="65">Wyoming</option></select> </div> </div> <div class="md-form pb-3"> <div class="form-group has-feedback"> <label for="inputCountry" class="control-label col-sm-6">Country:</label> <select name="country" required aria-required="true" aria-describedby="atCountry" id="inputCountry"><option value="" selected="selected">Please Select</option><option value="38">Canada</option><option value="223">United States</option></select> </div> </div> Quote Peter McGrath ----------------------------- See my Profile (click here) for more information and to contact me for professional osCommerce support that includes SEO development, custom development and security implementation Link to comment Share on other sites More sharing options...
Jack_mcs Posted November 4, 2021 Share Posted November 4, 2021 2 hours ago, cannuck1964 said: $(document).ready(function(){ Try replacing the above with this window.addEventListener('DOMContentLoaded', function() { //wait for jquery to load Quote Support Links: For Hire: Contact me for anything you need help with for your shop: upgrading, hosting, repairs, code written, etc. Get the latest versions of my addons Recommended SEO Addons Link to comment Share on other sites More sharing options...
♥cannuck1964 Posted November 4, 2021 Share Posted November 4, 2021 Thanks Jack, no did not work. I might just move past it, as my guess it is a conflict somewhere. I have a lot of JS on the site, looking to actually move all cart functions to AJAX calls. I use a lot of modals to login, create accounts etc. cheers Peter Quote Peter McGrath ----------------------------- See my Profile (click here) for more information and to contact me for professional osCommerce support that includes SEO development, custom development and security implementation Link to comment Share on other sites More sharing options...
Jack_mcs Posted November 6, 2021 Share Posted November 6, 2021 @cannuck1964If you haven't done so I suggest you enable the developer console for your browser so that you can see why the code is failing. The code I mentioned is needed in the newer shops because jquery isn't loaded until the end. But it might be that you have some minor mistake in the code, or something like that. Quote Support Links: For Hire: Contact me for anything you need help with for your shop: upgrading, hosting, repairs, code written, etc. Get the latest versions of my addons Recommended SEO Addons Link to comment Share on other sites More sharing options...
♥cannuck1964 Posted November 8, 2021 Share Posted November 8, 2021 I have the developer module running. did not think this would be a hard contribution to install, but this is the error : Uncaught ReferenceError: sn is not defined <anonymous> https://dev.mrboxonline.com/quote_history.php:127 Coming from this code: window.addEventListener('DOMContentLoaded', function() { if($("#inputCountry").val()==""){ $("#inputCountry").val('223'); } if($("#inputCountry").val()!=""){ $("label[for='inputState']+div").html(''),id_country=$("#inputCountry").val(),$.post("states.php",{country_id:id_country,state_name:sn},function(a){ $("label[for='inputState']+div").html(a) } ) } }); sn (state name) is not defined for some reason. cheers Peter Quote Peter McGrath ----------------------------- See my Profile (click here) for more information and to contact me for professional osCommerce support that includes SEO development, custom development and security implementation Link to comment Share on other sites More sharing options...
♥cannuck1964 Posted November 8, 2021 Share Posted November 8, 2021 And adding in the line: var sn=$("#inputState").val(); does not help. cheers Peter Quote Peter McGrath ----------------------------- See my Profile (click here) for more information and to contact me for professional osCommerce support that includes SEO development, custom development and security implementation Link to comment Share on other sites More sharing options...
Jack_mcs Posted November 8, 2021 Share Posted November 8, 2021 @cannuck1964 The developer consoles will return not defined for a number of reasons, not all of which have to do with what the error says. I think the problem is that this line doesn't have closure $("label[for='inputState']+div").html(a) and/or there is an extra } after it. When I get such a failure on a js function, I delete everything in it and just include an alert or console.log line. If the message shows up then you know the calling function is working. Then add in parts of the original code to see where it fails. Quote Support Links: For Hire: Contact me for anything you need help with for your shop: upgrading, hosting, repairs, code written, etc. Get the latest versions of my addons Recommended SEO Addons Link to comment Share on other sites More sharing options...
Demitry Posted November 9, 2021 Share Posted November 9, 2021 Quote sn (state name) is not defined for some reason. give this a try: window.addEventListener('DOMContentLoaded', function() { if ($("#inputCountry").val() == "") { $("#inputCountry").val("223"); } if ($("#inputCountry").val() != "") { $("label[for='inputState']+div").html(), (id_country = $("#inputCountry").val()), (sn = $("#inputState").val()), $.post("states.php", { country_id:id_country, state_name:sn }, function (a) { $("label[for='inputState']+div").html(a); }); } }); Quote osCommerce: made for programmers, ...because store owners do not want to be programmers. https://trends.google.com/trends/explore?date=all&geo=US&q=oscommerce Link to comment Share on other sites More sharing options...
♥cannuck1964 Posted November 9, 2021 Share Posted November 9, 2021 Thanks Demitry, but no, that does not work either. Normally I do not have a lot of issues with javascript, but this one is just not quite right. I suspect a conflict somewhere. Quote Peter McGrath ----------------------------- See my Profile (click here) for more information and to contact me for professional osCommerce support that includes SEO development, custom development and security implementation Link to comment Share on other sites More sharing options...
Demitry Posted November 9, 2021 Share Posted November 9, 2021 @cannuck1964 What version of osC are you using? And, did you just install this add-on, or was it there from some time back and just stopped working? I have BS Edge and the default code for the country/state pairing was problematic. I actually worked on this Country State Selector add-on, but for reasons I cannot recall now, I chose a different one. I installed Rainer's State Selector BS add-on and World Zones. https://apps. oscommerce.com/cbtGB&state-selector-bs Quote osCommerce: made for programmers, ...because store owners do not want to be programmers. https://trends.google.com/trends/explore?date=all&geo=US&q=oscommerce Link to comment Share on other sites More sharing options...
♥cannuck1964 Posted November 10, 2021 Share Posted November 10, 2021 My version of osC is 2.3.4++ I do a lot of upgrades and do not follow all of the osC releases. Tried the new one and same thing, no luck. I think I will try upgrading my jQuery and bootstrap versions, maybe that will help, not sure when I did so last. thanks Peter Demitry 1 Quote Peter McGrath ----------------------------- See my Profile (click here) for more information and to contact me for professional osCommerce support that includes SEO development, custom development and security implementation Link to comment Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.