Jump to content
stevel

Country-State Selector

Recommended Posts

Joe, please ask your web host about enabling PHP error logging or display.

 

Marc, you have a PHP syntax error - in this case, a missing close brace. You removed one, but perhaps it was in the wrong place rather than being extra. I suggest comparing your edited file against the pre-edited files provided in the zip file. This may help you spot the problem.

 

Ian, I was thinking about your page with the two address sections. Without some extra work, the code won't be able to tell which of the two country fields got changed. I suggest that you add two hidden fields that have a value of the current selection for country, call these old_country1 and old_country2, for example. Then when a refresh is seen, compare the current value of country1 (this is what I call the one in the left column) against old_country1. If it is the same, do NOT clear the state field. Same for country2 and old_country2.

Share this post


Link to post
Share on other sites

HI all,

 

I have the need to associate and divide all products to a particular area and I thought to use this contribution if it is adaptable.

 

ie:

Select first the COUNTRY from a drop down menu. Then all the areas in that country should be in another drop down menu. Therefore, all products associated to that areas, should be listed and be able to sort/filter by category/manufacturer.

 

is it possible to adapt this nice contribution in this way?

 

Thanks

 

Salvo

Edited by Salvo

Share this post


Link to post
Share on other sites

You can certainly apply the technique used to refresh the page and provide a dropdown of just the zones in the selected country (if any). You could extend it if you needed to further qualify a different dropdown. The basic idea is the use of an onChange JavaScript action to refresh the page and select choices for another item.

Share this post


Link to post
Share on other sites

Hi Steve,

I see that you are the creator of this nice contribution. Would you be interested in helping and of course create it as contribution?

 

I am sure that there are many people out there interested in something like this.

 

People can use it if there have some products that can only be sold in some locations.

 

Thank you

 

salvo

Share this post


Link to post
Share on other sites

Sorry, not really. I develop contribs that I want to use on my own store. If I have no use for something, I can't get too interested in writing it.

 

I think what you want more than something like this contrib is a way to require that the customer select their location before browsing products, and then you can filter on that when displaying products. It would be a pain to have to do this selection more than once in a session.

 

Depending on how many choices you offer, you might want to do the menu selection a different way (such as loading all the choices into a JavaScript array and filtering it).

Share this post


Link to post
Share on other sites

Steve,

Thanks for your input I appreciated it.

 

I will see if I can make it work.

 

Salvo

Edited by Salvo

Share this post


Link to post
Share on other sites
Ian,

 

I see a couple of problems. First, on the left column select tag for country, you have

 

onChange="return refresh_form(createaccount);"

 

However, the name of the form on that page is not createaccount, it is checkout.

 

Second, the field for the shipping country does not include the onChange action. That needs to be added.

 

A third problem, unrelated to this, is that your img tag for the "visual verifier" is malformed, missing the closing bracket.

 

I can't see your PHP code so you need to make sure that it properly establishes the country for both fields on a refresh.

 

hi Steve

 

I've fixed the 1st prob and that now refreshes OK. For the shipping part, doh!! didn't even occur to me, still ongoing. I'll also try your suggestion further down when my brain isn't as fried. The 3rd prob is fixed even tho it seemed to work.

 

A related question. Is it possible to make the country & state lists a default size instead of fitting to the text inside. If I set the country to USA, for example, the states box expands to fit the text and it screws the layout.

 

many thanks

 

Ian

Share this post


Link to post
Share on other sites

Nope - width of the dropdown list is entirely controlled by the browser based on the longest value. You have no control over this (other than shortening list values.) I recently researched this so it's fresh in my mind. Even if you put it in a fixed-width table cell, the browser will make the cell wider so that it fits. No horizontal scrolling.

Share this post


Link to post
Share on other sites
Nope - width of the dropdown list is entirely controlled by the browser based on the longest value. You have no control over this (other than shortening list values.) I recently researched this so it's fresh in my mind. Even if you put it in a fixed-width table cell, the browser will make the cell wider so that it fits. No horizontal scrolling.

Thanks Steve.

 

 

Ian

Share this post


Link to post
Share on other sites

Hi,

 

I integrated the contrib to my site.

 

The default country selector is working, but the page doesent reload on changing the country, the code for reload is there

 

<select name="country" onChange="return refresh_form(create_account);">

 

and I dont get any page errors.

 

I didnt install the /admin/... files as I dont need it in the admin section. Do I have to alter them also for functionality?

 

br,

mfred

Share this post


Link to post
Share on other sites

No, you don't need the admin changes. Please follow the troubleshooting tips in the readme. In particular, make sure that the refresh_form JavaScript function is present in the loaded page (view page source in your web browser) and that there are no JavaScript errors reported.

Share this post


Link to post
Share on other sites

steve thx for this fast reponse.

 

The JS part is in the loaded head section of the page:

 

function refresh_form(form_name) {
  form_name.action.value = 'refresh';
  form_name.submit();
  return true;
  }

 

Normally i am working with firefox which gave no errors. Loading the page in IE gives a syntax error on line 113 which is:

 

check_input("state", , "Das Bundesland sollte mindestens  Zeichen enthalten.");

On reloading the page this error disappears as it has then a state in the Fieldlist.

 

But on changing the country I get the following error: Missing object on line 404

 

<td class="main"><select name="country" onChange="return refresh_form(create_account);"><option value="">Bitte wählen</option><option value="2">Albania</option><option value="5">Andorra</option><option value="14" SELECTED>Austria</option>....[LONGLISTHERE] </select> <span class="inputRequirement">* (Seite lädt nach Auswahl neu)</span></td>

 

br,

mfred

Share this post


Link to post
Share on other sites

I found it out.

 

The problem was that the

'minimum value' for state in the admin menu was empty. I replaced it with a 0

then it worked :)

Share this post


Link to post
Share on other sites

I am having a problem while Register Globals are off on checkout_shipping_address.php and checkout_payment_address.php

When selecting the country in the drop down menu the page refresh and goes back to the "Please select". It works fine when register globals are on and all other pages except for these 2 files.

How can I fix this?

 

TIA

Edited by dr_lucas

Share this post


Link to post
Share on other sites

I seem to have made a mistake while editing these 2 files, so it works fine with register globals off.

 

I do have a different issue now, when the page refresh on these 2 files after selecting the country, there is still no dropdown menu in the state field. There is only the standard blank space that you can type it in, but no dropdown. It works fine on create account page and other pages when selecting the country. Any ideas?

Share this post


Link to post
Share on other sites

I have a problem with the state not clearing out when the country is changed. This is only happening on create_account, checkout_shipping_address and checkout_payment_address. The other pages admin_customers and address_book_process do not have this problem. I have spent hours and cannot figure it out. This does seem to be an ongoing problem with this mod and I DID download all of the supposed fixes for this problem and compared them to the newest updates and they are all the same. It looks like the three files with problems originally had the problem fixed with this line:

 if ($HTTP_POST_VARS['action'] == 'refresh') {$state = '';} 

but it is not clearing the state field when my form refreshes.

 

If anyone has had this problem and found a way to fix it please let me know. Register globals is ON and this is a fresh install with this being the first mod added to these pages. I apologize in advance if the fix is already posted in here but I browsed through all 39 pages and didn't find what I needed.

Share this post


Link to post
Share on other sites

Hi guys,

 

excellent contribution. I would also expect this to be in the new oscommerce core, for sure!!!

 

Everything works perfectly but....

 

I got 3 languages in my site (CatalanCooking) and dropdown boxes in create_account.php work well for english and spanish version but not catalan... :blink:

 

I can't understand what I'm missing. Any help apreciated, people.

 

Thanks in advance

Share this post


Link to post
Share on other sites

You put a font tag with a color in the text for the error messages for minimum name length, etc., in the Catalan file. You can't do that because the quote character in the string causes a JavaScript error. You don't have these in the English definitions.

Share this post


Link to post
Share on other sites

does everyone know how to put a onChange behavor of javascript into a dropdown menu

 

Ex: Dropdown menu in address_book_detail.php (or any dropdown menu)

 

echo tep_draw_pull_down_menu('state', $zones_array, $cur_zone_value['zone_name']);

 

And I want to put this javascripts onChange="javscript: handle_selection(document.getElementById('state').value);" into the that dropdown menu.

 

So it will come out like this in html:

 

<select name="something" id="something" onChange="javscript: handle_selection(document.getElementById('state').value);" ><option></option><option></option></selection

 

Thanks in advance!

 

 

Congiothoang

Edited by congiothoang

Share this post


Link to post
Share on other sites

Steve, many thanks. I hope one day I have such clear knowledge and find problems as fast as you, guy!!

 

Many thanks!!!

Share this post


Link to post
Share on other sites

Thanks Steve I actually did it and everything works on both sites now God Bless you for all your help and patients.

 

Judy

Share this post


Link to post
Share on other sites
does everyone know how to put a onChange behavor of javascript into a dropdown menu

 

Ex: Dropdown menu in address_book_detail.php (or any dropdown menu)

 

echo tep_draw_pull_down_menu('state', $zones_array, $cur_zone_value['zone_name']);

 

And I want to put this javascripts onChange="javscript: handle_selection(document.getElementById('state').value);" into the that dropdown menu.

 

So it will come out like this in html:

 

<select name="something" id="something" onChange="javscript: handle_selection(document.getElementById('state').value);" ><option></option><option></option></selection

 

Thanks in advance!

Congiothoang

I'm not using your mod but I thought I could help. It's pretty simply actually.

According to the documentation, these are the possibilities for this function:

tep_draw_pull_down_menu($name, $values, $default = '', $parameters = '', $required = false) 

 

The Fourth part is for your own custom parameters. Just add a coma after your default selection and put your parameters between two single quotes.

 

For example:

tep_draw_pull_down_menu('state', $zones_array, $cur_zone_value['zone_name'],'onChange="javscript: handle_selection(document.getElementById('state').value);"') 

 

Cheers! :)

Share this post


Link to post
Share on other sites

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 account

Sign in

Already have an account? Sign in here.

Sign In Now

×