I'm improving a checkout page and have 2 identical 'country select' menus. One at the top of the page to calculate postage, and one at the bottom for entering delivery address. Our customers seem to have a lot of difficulty grasping that they need to pick the same country in both menus, or the price calculation will be incorrect.
So what i'm trying to do is to make a change on one menu update its pair and vice versa. At the moment, the first menu (menu A) that I change works fine repeatedly (affects menu B) but once menu A has been changed, changed to menu B are not picked up. Same thing in reverse, if menu B is changed first, changes to menu A are not picked up by the javascript.
The menus are written back into the page with the appropriate option selected. I was wondering if it is this re-writing with ajax that stops the menu from being able to be watched in the jquery.
Here's the full script (the UPDATE MENU... bits are the important functions, just thought I would leave the rest of my functions in the script in case they were causing a problem)
// wait for the DOM to be loaded
$(document).ready(function() {
// see if countryIsoTop menu has changed
$("#countryIsoTop").change(function() {
// UPDATE MENU IN SHIPPING OPTIONS
$.ajax({
type: "POST",
url: "incViewbasketShippingBoxes.php",
data: $("#checkoutform").serialize(),
success: function(response) {
$('#shippingBoxes').html(response);
}
});
// prevent actual form submission
return false;
});
// see if countryIsoShipping menu has changed
$("#countryIsoShipping").change(function() {
// UPDATE MENU IN TOP COUNTRY BOX
var data = 'countryIsoShipping=' + $("#countryIsoShipping").val();
$.ajax({
type: "POST",
url: "incViewbasketCountryChooser.php",
data: data,
success: function(response) {
$('#countryIsoTopBox').html(response);
}
});
// prevent actual form submission
return false;
});
});
Here is the HTML
<div name="countryIsoTopBox" id="countryIsoTopBox">
<?
require("incViewbasketCountryChooser.php");
?>
</div>
...
<div id="shippingBoxes">
<?
require("incViewbasketShippingBoxes.php");
?>
</div>
Here is an example of what the php produces
<select name="countryIsoTop" id="countryIsoTop">
<option value="">Choose delivery country</option>
<option value="AF">Afghanistan</option>
.
.
.
</select>
and
<select name="countryIsoShipping" id="countryIsoShipping">
<option value="">Choose delivery country</option>
<option value="AF">Afghanistan</option>
.
.
.
</select>