Skip to content

Instantly share code, notes, and snippets.

@pale2hall
Created February 27, 2017 19:54
Show Gist options
  • Save pale2hall/85b44161559f665639ec5107db96b014 to your computer and use it in GitHub Desktop.
Save pale2hall/85b44161559f665639ec5107db96b014 to your computer and use it in GitHub Desktop.
Prevent osCommerce from showing Alabama instead of the correct state.
/*
Installation:
Add this script right before the closing </body> tag in your /catalog/includes/template_bottom.php
Tested on a heavily modified installation of osCommerce v2.3.x
Explanation:
Once a page is loaded, this code checks to see if there's a <select> drop down box on the page with
the name of "state". The Create Account page and the edit your address book pages both use this
Select field. If a customer makes a mistake, and types the state wrong, and has some other issue with
their input, like an email address that already exists in the database, the customer is redirected back
to the page with the form. If there is Not a value with the Selected attribute, which implies they
did not enter the state correctly, an additional <option>Please Select</option> is added to the list,
and selected. This will prevent the customer from submitting Please Select due to the minimum # of chars
osCommerce validates for before submitting the form. By Default, the state list is just sorted A-Z, and
customers will accidentally submit Alabama without realizing.
Please let me know if you have any issues with this code snippet.
*/
<script>
jQuery(document).ready(function($) {
if (!$('select[name=state]>option[selected=selected]').length){
$('select[name=state]').prepend('<option value="" selected="selected">Please Select!</option>');
}
});
</script>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment