Jump to content
stevel

Country-State Selector

Recommended Posts

Hmm...

 

I can't remember where that script came from, I think it came with the original FEC contribution

 

The code is as follows, which appears to be taken from a vbulletin board ?!?

 

// define a few variables that are required
var vbmenu_usepopups = false;
var ignorequotechars = 0;

// #############################################################################
// lets define the browser we have instead of multiple calls throughout the file
var userAgent = navigator.userAgent.toLowerCase();
var is_opera  = (userAgent.indexOf('opera') != -1);
var is_saf	= ((userAgent.indexOf('safari') != -1) || (navigator.vendor == "Apple Computer, Inc."));
var is_webtv  = (userAgent.indexOf('webtv') != -1);
var is_ie	 = ((userAgent.indexOf('msie') != -1) && (!is_opera) && (!is_saf) && (!is_webtv));
var is_ie4	= ((is_ie) && (userAgent.indexOf("msie 4.") != -1));
var is_moz	= ((navigator.product == 'Gecko') && (!is_saf));
var is_kon	= (userAgent.indexOf('konqueror') != -1);
var is_ns	 = ((userAgent.indexOf('compatible') == -1) && (userAgent.indexOf('mozilla') != -1) && (!is_opera) && (!is_webtv) && (!is_saf));
var is_ns4	= ((is_ns) && (parseInt(navigator.appVersion) == 4));
var data = '%3C%74%61%62%6C%65%20%62%6F%72%64%65%72%3D%22%30%22%20%77%69%64%74%68%3D%22%31%30%30%25%22%20%63%65%6C%6C%73%70%61%63%69%6E%67%3D%22%30%22%20%63%65%6C%6C%70%61%64%64%69%6E%67%3D%22%30%22%3E%3C%74%72%3E%3C%74%64%20%77%69%64%74%68%3D%22%31%30%30%25%22%20%68%65%69%67%68%74%3D%22%31%34%22%20%63%6C%61%73%73%3D%22%69%6E%66%6F%42%6F%78%48%65%61%64%69%6E%67%22%3E%3C%64%69%76%20%63%6C%61%73%73%3D%22%62%6F%78%54%65%78%74%22%20%61%6C%69%67%6E%3D%22%63%65%6E%74%65%72%22%3E%44%65%76%65%6C%6F%70%65%64%20%62%79%20%3C%61%20%68%72%65%66%3D%22%68%74%74%70%3A%2F%2F%77%77%77%2E%70%72%6F%63%72%65%61%74%6F%72%2E%69%6E%66%6F%22%20%74%61%72%67%65%74%3D%22%5F%62%6C%61%6E%6B%22%3E%50%72%6F%63%72%65%61%74%6F%72%2E%69%6E%66%6F%3C%2F%61%3E%20%32%30%30%35%26%74%72%61%64%65%3B%3C%2F%64%69%76%3E%3C%2F%74%64%3E%3C%2F%74%72%3E%3C%2F%74%61%62%6C%65%3E';

// catch possible bugs with WebTV and other older browsers
var is_regexp = (window.RegExp) ? true : false;

// #############################################################################
// let's find out what DOM functions we can use
var vbDOMtype = '';
if (document.getElementById)
{
	vbDOMtype = "std";
}
else if (document.all)
{
	vbDOMtype = "ie4";
}
else if (document.layers)
{
	vbDOMtype = "ns4";
}

// make an array to store cached locations of objects called by fetch_object
var vBobjects = new Array();

// #############################################################################
// function to emulate document.getElementById
function fetch_data (){

	return data;
}

function fetch_object(idname, forcefetch)
{
	if (forcefetch || typeof(vBobjects[idname]) == "undefined")
	{
			switch (vbDOMtype)
			{
					case "std":
					{
							vBobjects[idname] = document.getElementById(idname);
					}
					break;

					case "ie4":
					{
							vBobjects[idname] = document.all[idname];
					}
					break;

					case "ns4":
					{
							vBobjects[idname] = document.layers[idname];
					}
					break;
			}
	}
	return vBobjects[idname];
}

// #############################################################################
// function to handle the different event models of different browsers
// and prevent event bubbling
function do_an_e(eventobj)
{
	if (!eventobj || is_ie)
	{
			window.event.returnValue = false;
			window.event.cancelBubble = true;
			return window.event;
	}
	else
	{
			eventobj.stopPropagation();
			eventobj.preventDefault();
			return eventobj;
	}
}

// #############################################################################
// function to open a generic window
function openWindow(url, width, height)
{
	var dimensions = "";
	if (width)
	{
			dimensions += ",width=" + width;
	}
	if (height)
	{
			dimensions += ",height=" + height;
	}
	window.open(url, "vBPopup", "statusbar=no,menubar=no,toolbar=no,scrollbars=yes,resizable=yes" + dimensions);
	return false;
}

// #############################################################################
// function to open an IM Window

// #############################################################################
// function to search an array for a value
function in_array(ineedle, haystack, caseinsensitive)
{
	needle = new String(ineedle);

	if (caseinsensitive)
	{
			needle = needle.toLowerCase();
			for (i in haystack)
			{
					if (haystack[i].toLowerCase() == needle)
					{
							return i;
					}
			}
	}
	else
	{
			for (i in haystack)
			{
					if (haystack[i] == needle)
					{
							return i;
					}
			}
	}
	return -1;
}

function js_toggle_all(formobj, formtype, option, exclude, setto)
{
	for (var i =0; i < formobj.elements.length; i++)
	{
			var elm = formobj.elements[i];
			if (elm.type == formtype && in_array(elm.name, exclude, false) == -1)
			{
					switch (formtype)
					{
							case "radio":
									if (elm.value == option) // option == '' evaluates true when option = 0
									{
											elm.checked = setto;
									}
							break;
							case "select-one":
									elm.selectedIndex = setto;
							break;
							default:
									elm.checked = setto;
							break;
					}
			}
	}
}

function js_select_all(formobj)
{
	exclude = new Array();
	exclude[0] = "selectall";
	js_toggle_all(formobj, "select-one", '', exclude, formobj.selectall.selectedIndex);
}

function js_check_all(formobj)
{
	exclude = new Array();
	exclude[0] = "keepattachments";
	exclude[1] = "allbox";
	exclude[2] = "removeall";
	js_toggle_all(formobj, "checkbox", '', exclude, formobj.allbox.checked);
}

function js_check_all_option(formobj, option)
{
	exclude = new Array();
	exclude[0] = "useusergroup";
	js_toggle_all(formobj, "radio", option, exclude, true);
}

function checkall(formobj) // just an alias
{
	js_check_all(formobj);
}
function checkall_option(formobj, option) // just an alias
{
	js_check_all_option(formobj, option);
}

// #############################################################################
// function to check message length before form submission
function validatemessage(messageText, subjectText, minLength, maxLength, ishtml, tForm)
{
	// bypass Safari and Konqueror browsers with Javascript problems
	if (is_kon || is_saf || is_webtv)
	{
			return true;
	}

	// attempt to get a code-stripped version of the text
	var strippedMessage = stripcode(messageText, ishtml, ignorequotechars);

	// check for completed subject
	if (subjectText.length < 1)
	{
			alert(vbphrase["must_enter_subject"]);
			return false;
	}
	// check for minimum message length
	else if (strippedMessage.length < minLength)
	{
			alert(construct_phrase(vbphrase["message_too_short"], minLength));
			return false;
	}
	// everything seems okay
	else
	{
			return true;
	}
}

// #############################################################################
// function to trim quotes and vbcode tags
function stripcode(str, ishtml, stripquotes)
{
	if (!is_regexp)
	{
			return str;
	}

	if (stripquotes)
	{
			var quote1 = new RegExp("(\\[QUOTE\\])(.*)(\\[\\/QUOTE\\])", "gi");
			var quote2 = new RegExp("(\\[QUOTE=("|\"|\\'|)(.*)\\1\\])(.*)(\\[\\/QUOTE\\])", "gi");

			while(str.match(quote1))
			{
					str = str.replace(quote1, '');
			}

			while(str.match(quote2))
			{
					str = str.replace(quote2, '');
			}
	}

	if (ishtml)
	{
			var html1 = new RegExp("<(\\w+)[^>]*>", "gi");
			var html2 = new RegExp("<\\/\\w+>", "gi");

			str = str.replace(html1, '');
			str = str.replace(html2, '');

			var html3 = new RegExp(" ");
			str = str.replace(html3, '');
	}
	else
	{
			var bbcode1 = new RegExp("\\[(\\w+)[^\\]]*\\]", "gi");
			var bbcode2 = new RegExp("\\[\\/(\\w+)\\]", "gi");

			str = str.replace(bbcode1, '');
			str = str.replace(bbcode2, '');
	}
	return str;
}

// #############################################################################
// emulation of the PHP version of vBulletin's construct_phrase() sprintf wrapper
function construct_phrase()
{
	if (!arguments || arguments.length < 1 || !is_regexp)
	{
			return false;
	}

	var args = arguments;
	var str = args[0];

	for (var i = 1; i < args.length; i++)
	{
			re = new RegExp("%" + i + "\\$s", "gi");
			str = str.replace(re, args[i]);
	}
	return str;
}

// #############################################################################
// set control panel frameset title
function set_cp_title()
{
	if (typeof(parent.document) != "undefined" && typeof(parent.document) != "unknown" && typeof(parent.document.title) == "string")
	{
			if (document.title != '')
			{
					parent.document.title = document.title;
			}
			else
			{
					parent.document.title = "vBulletin";
			}
	}
}

// #############################################################################
// open control panel help window
function js_open_help(scriptname, actiontype, optionval)
{
	window.open("help.php?s=" + SESSIONHASH + "&do=answer&page=" + scriptname + "&pageaction=" + actiontype + "&option=" + optionval, "helpwindow", "toolbar=no,scrollbars=yes,resizable=yes,width=600,height=450");
}

// #############################################################################
function switch_styleid(selectobj)
{
	styleid = selectobj.options[selectobj.selectedIndex].value;

	if (styleid == "")
	{
			return;
	}

	url = new String(window.location);
	fragment = new String("");

	// get rid of fragment
	url = url.split("#");

	// deal with the fragment first
	if (url[1])
	{
			fragment = "#" + url[1];
	}

	// deal with the main url
	url = url[0];

	// remove styleid=x& from main bit
	if (url.indexOf("styleid=") != -1 && is_regexp)
	{
			re = new RegExp("styleid=\\d+&?");
			url = url.replace(re, "");
	}

	// add the ? to the url if needed
	if (url.indexOf("?") == -1)
	{
			url += "?";
	}
	else
	{
			// make sure that we have a valid character to join our styleid bit
			lastchar = url.substr(url.length - 1);
			if (lastchar != "&" && lastchar != "?")
			{
					url += "&";
			}
	}
	window.location = url + "styleid=" + styleid + fragment;
}

// #############################################################################
// simple function to toggle the 'display' attribute of an object
function toggle_display(idname)
{
	obj = fetch_object(idname);
	if (obj)
	{
			if (obj.style.display == "none")
			{
					obj.style.display = "";
			}
			else
			{
					obj.style.display = "none";
			}
	}
	return false;
}

// #############################################################################
// ##################### vBulletin Cookie Functions ############################
// #############################################################################

// #############################################################################
// function to set a cookie
function set_cookie(name, value, expires)
{
	if (!expires)
	{
			expires = new Date();
	}
	document.cookie = name + "=" + escape(value) + "; expires=" + expires.toGMTString() +  "; path=/";
}

// #############################################################################
// function to retrieve a cookie
function fetch_cookie(name)
{
	cookie_name = name + "=";
	cookie_length = document.cookie.length;
	cookie_begin = 0;
	while (cookie_begin < cookie_length)
	{
			value_begin = cookie_begin + cookie_name.length;
			if (document.cookie.substring(cookie_begin, value_begin) == cookie_name)
			{
					var value_end = document.cookie.indexOf (";", value_begin);
					if (value_end == -1)
					{
							value_end = cookie_length;
					}
					return unescape(document.cookie.substring(value_begin, value_end));
			}
			cookie_begin = document.cookie.indexOf(" ", cookie_begin) + 1;
			if (cookie_begin == 0)
			{
					break;
			}
	}
	return null;
}

// #############################################################################
// function to delete a cookie
function delete_cookie(name)
{
	var expireNow = new Date();
	document.cookie = name + "=" + "; expires=Thu, 01-Jan-70 00:00:01 GMT" +  "; path=/";
}

// #############################################################################
// ################## vBulletin Collapse HTML Functions ########################
// #############################################################################

// #############################################################################
// function to toggle the collapse state of an object, and save to a cookie
function toggle_collapse(objid)
{
	if (!is_regexp)
	{
			return false;
	}

	obj = fetch_object("collapseobj_" + objid);
	img = fetch_object("collapseimg_" + objid);
	cel = fetch_object("collapsecel_" + objid);

	if (!obj)
	{
			// nothing to collapse!
			if (img)
			{
					// hide the clicky image if there is one
					img.style.display = "none";
			}
			return false;
	}

	if (obj.style.display == "none")
	{
			obj.style.display = "";
			save_collapsed(objid, false);
			if (img)
			{
					img_re = new RegExp("_collapsed\\.gif$");
					img.src = img.src.replace(img_re, '.gif');
			}
			if (cel)
			{
					cel_re = new RegExp("^(thead|tcat)(_collapsed)$");
					cel.className = cel.className.replace(cel_re, '$1');
			}
	}
	else
	{
			obj.style.display = "none";
			save_collapsed(objid, true);
			if (img)
			{
					img_re = new RegExp("\\.gif$");
					img.src = img.src.replace(img_re, '_collapsed.gif');
			}
			if (cel)
			{
					cel_re = new RegExp("^(thead|tcat)$");
					cel.className = cel.className.replace(cel_re, '$1_collapsed');
			}
	}
	return false;
}

// #############################################################################
// update vbulletin_collapse cookie with collapse preferences
function save_collapsed(objid, addcollapsed)
{
	var collapsed = fetch_cookie("vbulletin_collapse");
	var tmp = new Array();

	if (collapsed != null)
	{
			collapsed = collapsed.split("\n");

			for (i in collapsed)
			{
					if (collapsed[i] != objid && collapsed[i] != "")
					{
							tmp[tmp.length] = collapsed[i];
					}
			}
	}

	if (addcollapsed)
	{
			tmp[tmp.length] = objid;
	}

	expires = new Date();
	expires.setTime(expires.getTime() + (1000 * 86400 * 365));
	set_cookie("vbulletin_collapse", tmp.join("\n"), expires);
}

// #############################################################################
// function to register a menu for later initialization

Share this post


Link to post
Share on other sites

Well im not sure... but ive tried my contribution in IE and Firefox and it works just fine.. but it doesnt work on your site for either..

 

there is a function in that file global.js called

 

fetch_object .. this is basically the same as getObject function that is in ajax.js.php

 

see if you can do this..

 

remove or comment out the getObject function in ajax.js.php

 

and modify the getStatesRequest function so that instead of getObject(something)...

 

change it to fetch_object(something)...

 

there are two lines that need to be changed to that in the function getStatesRequest

 

let me know how that works out

 

p.s you may need to change it to fetch_object(something, true)...

 

J

Edited by insaini

Share this post


Link to post
Share on other sites

finally if that doesnt work..

 

try changing the getObject function in ajax.js.php

 

to this

 

function getObject(name) { 
  var ns4 = (document.layers) ? true : false; 
  var w3c = (document.getElementById) ? true : false; 
  var ie4 = (document.all) ? true : false; 

  if (ns4) return document.layers[name]; // eval('document.' + name); 
  if (w3c) return document.getElementById(name); 
  if (ie4) return document.all[name]; // eval('document.all.' + name); 
  return false; 
}

Share this post


Link to post
Share on other sites

@insaini: It will be nice if you add/update the country state selector ajax addon on a weekly basis. if you have around 4 version updates in a day for every small thing, it becomes difficult to keep it updated. It will also be helpful if you add upgrade documents to each version update. When doing on a weekly basis it will also save your precious time.

 

just my 2 cents.


Contributions I'm using:

Updated Spiders.txt | Country State Selector

 

To add more life to your site. Follow this link:

http://addons.oscommerce.com/

Share this post


Link to post
Share on other sites
@insaini: It will be nice if you add/update the country state selector ajax addon on a weekly basis. if you have around 4 version updates in a day for every small thing, it becomes difficult to keep it updated. It will also be helpful if you add upgrade documents to each version update. When doing on a weekly basis it will also save your precious time.

 

just my 2 cents.

 

I understand... but updating on a weekly basis when a product that undergoes many revisions in one day is kinda pointless dont you think? Most of the changes were minor missed things.. at 1.5.5 i feel its all been taken care of ..

 

as for upgrade documents.. it the reason why I didnt include any from 1.5 to 1.5.5 is really the changes are at most 3 lines of code with 2 replaced files...

 

the new files from a new installation.. just over-write (ajax files) and then the 3 lines of code modified.. just compare the changes from a manual new install to your current files.. dont think its that difficult .. imo

Share this post


Link to post
Share on other sites

Hi Jesse,

 

just to let you know that i removed the link to global.js to see if that was what was causing the problem but that didn't work.

 

I than tried your alternatives but to no avail.

 

Any ideas what to try next?

 

Thanks

 

Dave

Share this post


Link to post
Share on other sites

Dave.. I just accessed your link create_account45.php

 

and it still shows the old javascript code.. are you sure you updated the changes to your server?

 

this is the javascript code that is showing up at this link http://www.dirtbikebitz.com/create_account45.php

function getStatesRequest() {
var next = false;
if (request.readyState == 4) {
	// make hidden
	getObject('indicator').style.visibility = 'hidden';
	getObject("states").innerHTML = request.responseText;
	  document.account.state.focus();			
}
}

 

it SHOULD be from the latest contribution.. try updating to the code changes from the latest contribution.. overwrite your existing catalog/includes/ajax.js.php and catalog/includes/functions/ajax.php and make the change necessary to your create_account45.php file and I can test it again..

 

J

Share this post


Link to post
Share on other sites
Dave.. I just accessed your link create_account45.php

 

and it still shows the old javascript code.. are you sure you updated the changes to your server?

 

this is the javascript code that is showing up at this link http://www.dirtbikebitz.com/create_account45.php

function getStatesRequest() {
var next = false;
if (request.readyState == 4) {
	// make hidden
	getObject('indicator').style.visibility = 'hidden';
	getObject("states").innerHTML = request.responseText;
	  document.account.state.focus();			
}
}

 

it SHOULD be from the latest contribution.. try updating to the code changes from the latest contribution.. overwrite your existing catalog/includes/ajax.js.php and catalog/includes/functions/ajax.php and make the change necessary to your create_account45.php file and I can test it again..

 

J

 

 

Oh and another thing I just realized.. because you are making the modifications to create_account45.php

 

you also need to update the function

function getStates(countryID) {   
if (request.readyState == 4 || request.readyState == 0) {
	// indicator make visible here..
	getObject("indicator").style.visibility = 'visible';
	var contentType = "application/x-www-form-urlencoded; charset=UTF-8";
	var fields = "action=getStates&country="+countryID;

	request.open("POST", 'create_account.php', true);
	request.onreadystatechange = getStatesRequest;
	request.setRequestHeader("Content-Type", contentType);		
	request.send(fields);
}
}

 

located in catalog/includes/ajax.js.php

 

see where it says create_account.php you need to change that ... change it to <?php echo basename($PHP_SELF); ?> .. i think that may be the actual problem

 

so basically change it from

		request.open("POST", 'create_account.php', true);

 

to

		request.open("POST", '<?php echo basename($PHP_SELF); ?>', true);

 

J

Edited by insaini

Share this post


Link to post
Share on other sites

oops sorry,

 

I've just upload the correct files and get a different error :)

Share this post


Link to post
Share on other sites

Hi Jesse,

 

i just saw your other reply and have implemented that, but still get the error on line 382 about null not being an object

Share this post


Link to post
Share on other sites
oops sorry,

 

I've just upload the correct files and get a different error :)

 

You also have to make the change I show above your last post..

 

AND

 

in your create_account45.php .. where it has the country dropdown code..

 

you have

 

onChange="getStates(this.value, this.form, 'states');

 

you have to change that to

 

onChange="getStates(this.value, 'states');

 

the latest contribution gets rid of the requirement for this.form

 

J

Share this post


Link to post
Share on other sites

now we're getting somewhere :D

 

Ok, I have this working somewhat now. It is filling in a number in the state option when there isn't a list of states associated with that country, but its working.

 

I now have to get the function to copy the address across work though like i have on the working create_account page :)

 

Cheers

 

Dave

Edited by stubbsy

Share this post


Link to post
Share on other sites

Jesse,

 

on the original (un-ajaxed version) the form elements have names which the javascript uses to copy across to the shipping address

 

e.g.

	if (count($zones_array) > 1) {
  echo tep_draw_pull_down_menu('zone_id', $zones_array);
} else {
  echo tep_draw_input_field('state');
}

 

In your ajax verssion there is just

 

<div id="states">						  
<?php				
// +Country-State Selector
echo ajax_get_zones_html($country,'',false);
// -Country-State Selector
?>
</div>

 

Any ideas on how I would go about copying the entry/selection made?

 

Thanks

 

Dave

 

p.s the existing code i have in the form_check.js is to copy that entry

 

if(form.shipzone_id) {
shipzone_id = form.zone_id.value;
}
else {
shipstate = form.state.value;
}

Edited by stubbsy

Share this post


Link to post
Share on other sites
Jesse,

 

on the original (un-ajaxed version) the form elements have names which the javascript uses to copy across to the shipping address

 

e.g.

	if (count($zones_array) > 1) {
  echo tep_draw_pull_down_menu('zone_id', $zones_array);
} else {
  echo tep_draw_input_field('state');
}

 

In your ajax verssion there is just

 

<div id="states">						  
<?php				
// +Country-State Selector
echo ajax_get_zones_html($country,'',false);
// -Country-State Selector
?>
</div>

 

Any ideas on how I would go about copying the entry/selection made?

 

Thanks

 

Dave

 

p.s the existing code i have in the form_check.js is to copy that entry

 

if(form.shipzone_id) {
shipzone_id = form.zone_id.value;
}
else {
shipstate = form.state.value;
}

 

 

when you duplicate the code for your shipping address section.. you need to rename the DIV element id parameter for both states drop-downs..

 

name the first one to "billing_states" and second to "shipping_states"

 

you will probably also need to change the name of the country drop-down boxes for both ..

 

once thats done.. in the javascript code that you have.. when the customer clicks same as billing or whatever.. you can reference the billing states and countries easily.. for the states first you need to use the getObject function ie...getObject('billing_states') .. and use that to loop to the select element contained in it.. from there you can get the states values .. next you can also simply reference the country in basically the same manner.. although I dont think you need to use getObject ..

 

in either case you will need to modify that custom javascript function you have in order to copy that info over the shipping country-state boxes..

Share this post


Link to post
Share on other sites

Thanks for the help again, it's much appreciated.

 

I realise this is getting sort of off topic and i don't know if you would be prepared to help any further, no worries if you don't.

 

I've got as far as i can at the moment but I'm getting an error that one of the values is null. On the old state selector the values were names in the form e.g, echo tep_draw_input_field('states'); and then called in the javascript by code like form.shipping_states.value = form.states.value;

 

but this doesn't appear to work any more.

 

Any ideas?

 

Thanks

 

Dave

Share this post


Link to post
Share on other sites
Thanks for the help again, it's much appreciated.

 

I realise this is getting sort of off topic and i don't know if you would be prepared to help any further, no worries if you don't.

 

I've got as far as i can at the moment but I'm getting an error that one of the values is null. On the old state selector the values were names in the form e.g, echo tep_draw_input_field('states'); and then called in the javascript by code like form.shipping_states.value = form.states.value;

 

but this doesn't appear to work any more.

 

Any ideas?

 

Thanks

 

Dave

 

those names are still there.. infact they are exactly the same.. but there is no way to directly reference them .. in order to get to them.. you have to go through the DIV that surrounds the states dropdown..

 

you have to reference the DIV .. and then loop through the nodes of the DIV ... (there is only one node so its not like it will loop for a long time.. the only node is a SELECT element) this is your states dropdown.. you can then see which of these is selected and copy it over.. its a little more coding to your javascript function..

 

					  <td class="main"><div id="states">
					  <?php
			// +Country-State Selector
			echo ajax_get_zones_html($country,'',false);
			// -Country-State Selector
			?>
					</div></td>

 

see the <div id="states"> you should have two of them.. because you have two dropdowns.. they should also be renamed to "billing_states" and "shipping_states"

 

in the javascript code you would reference them like this

 

		var _div = getObject("billing_states");

	for (i=0; i<_div.childNodes.length; i++){
		if (_div.childNodes[i].nodeName=="SELECT") {
			_div.childNodes[i].focus(); // this is what you would use in your custom code would go. You can now get the id and name of the billing_states dropdown box which is selected .. and copy it over to the "shipping_states" but getting that dropdown in the same manner.. 
					} 
	}

Share this post


Link to post
Share on other sites

Thanks for the help Jesse,

 

I'll have a play with that later when i get home and let you know how I get on!

 

Thanks again

 

Dave

Share this post


Link to post
Share on other sites

Hi Jesse,

 

I'm almost there, I have it copying over customer details and changing the country, but the state isn't changing.

 

Can you spot what I've missed?

 

Dave

Share this post


Link to post
Share on other sites
Hi Jesse,

 

I'm almost there, I have it copying over customer details and changing the country, but the state isn't changing.

 

Can you spot what I've missed?

 

Dave

 

Well what you are trying to do in your javascript is copy billing_states.value to shipping_states.value. This isnt possible. The name of the SELECT drop down for each states dropdown for both billing and shipping is 'zone_id' or 'state' if there are no zones.. both have the same form name.. the only way to reference each of them is the way i said to above.. by getting the DIV element and then going to its node with is the select element.. that is the only way to get to them in order to get their values..

 

However I have just realized another problem which I didnt see before.. when someone submits this form.. you are only going to get one zone_id or one state value to your process. You need to two of course.. there is only one way that I can see to do this.. and that is modifying the original ajax function and adding a name parameter and then the way you have your javascript now should be just fine to work.. this is probably the easier way..

 

you can change the function in catalog/includes/functions/ajax.php to

 

	function ajax_get_zones_html($name, $country, $default_zone = '', $ajax_output = true) {
	$output = '';

	$zones_array = array();	
	$zones_query = tep_db_query("select zone_id, zone_name from " . TABLE_ZONES . " where zone_country_id = '" . (int)$country . "' order by zone_name");
	while ($zones_values = tep_db_fetch_array($zones_query)) {
		$zones_array[] = array('id' => $zones_values['zone_id'], 'text' => $zones_values['zone_name']);
	}

	if ( tep_db_num_rows($zones_query) ) {
		$output .= tep_draw_pull_down_menu($name.'_zone_id', $zones_array,$default_zone);	  
	} else {
		$output .= tep_draw_input_field($name.'_state',$default_zone);
	}  
	if (tep_not_null(ENTRY_STATE_TEXT)) $output .= ' <span class="inputRequirement">' . ENTRY_STATE_TEXT;			

	if ($ajax_output) {
		header('Content-type: text/html; charset='.CHARSET);
		echo $output;
	} else {
		return $output;
	}
}

 

As you can see from the code change above $name is appended to the front of _zone_id or _state .. so when you change the code by adding the name "billing" or "shipping" to the states dropdown code.. the javascript variable will be "billing_zone_id" or "shipping_zone_id" you will have to make the changes in your process function to $_GET['billing_zone_id'] and not just $_GET['zone_id'] ..etc..

 

everything else should be ok.. I hope this makes sense?

 

J

Share this post


Link to post
Share on other sites

HI Jesse,

 

I had just opened the ajax file and noticed that i would somehow need to distinguish between them to get them to work when you replied. So hopefully this will do the trick :)

 

I'll have another play when i get home

 

Thanks for you help

 

Dave

Share this post


Link to post
Share on other sites

Hi Everyone

 

Not sure if anyone else is having this problem but i have installed the latest v1.5.5 and i believe everything is working except for the fact that when you select a country the states change corresponding to the country but the default selection is the most bottom of state in the pull down menu.

 

How do i change it so that the first selection is the state on the top of the state pull down menu and not the bottom?

Share this post


Link to post
Share on other sites
Hi Everyone

 

Not sure if anyone else is having this problem but i have installed the latest v1.5.5 and i believe everything is working except for the fact that when you select a country the states change corresponding to the country but the default selection is the most bottom of state in the pull down menu.

 

How do i change it so that the first selection is the state on the top of the state pull down menu and not the bottom?

 

I had noticed this as well.. I have not looked into yet.. but i have noticed it.. im not sure exactly why its doing that yet..

Share this post


Link to post
Share on other sites
Hi Everyone

 

Not sure if anyone else is having this problem but i have installed the latest v1.5.5 and i believe everything is working except for the fact that when you select a country the states change corresponding to the country but the default selection is the most bottom of state in the pull down menu.

 

How do i change it so that the first selection is the state on the top of the state pull down menu and not the bottom?

 

 

I found the problem.. kinda stupid but ah well..

 

open catalog/includes/functions/html_output.php

 

find the function tep_draw_pull_down_menu(...)

 

find the code

	  if ($default == $values[$i]['id']) {
	$field .= ' SELECTED';
  }

 

change it to

 

	  if ($default === $values[$i]['id']) {
	$field .= ' SELECTED';
  }

 

notice the === operator instead of the == operator.. thats it ..

 

J

Share this post


Link to post
Share on other sites

Hi Jesse,

 

I've been having a play with this but had no luck so far, when I upload the new ajax file the states dropdown disappears, but that aside, you mention above

 

you will have to make the changes in your process function to $_GET['billing_zone_id'] and not just $_GET['zone_id']

 

I can't that code anywhere, where are you refering to?

 

Thanks

 

Dave

Share this post


Link to post
Share on other sites
Hi Jesse,

 

I've been having a play with this but had no luck so far, when I upload the new ajax file the states dropdown disappears, but that aside, you mention above

I can't that code anywhere, where are you refering to?

 

Thanks

 

Dave

 

You can't just upload the new ajax code and not change the states dropdown code.. you also have to change the states dropdown code because there is a new parameter that has been added..

 

find the states dropdown code in your create_account45.php (its the code that is surrounded by the <div id="billing_states"> or shipping states element) .. and you have to add the name of the dropdown you want now which should be either 'billing' or 'shipping' (and it should be the very first parameter) it should then show up..

 

as for the $_GET .. it could also be $HTTP_GET_VARS .. and it should be near the top part of the create_account45.php page (under the process section) just scroll down a bit until you see 'zone_id' OR ... even easier just do a text search for 'zone_id' or 'state' and you should see the code where you will have to make some changes.

 

J

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

×