http://jsfiddle.net/jeepstone/kxuMC/
if($('#deliveryPostcodeEstimator').length > 0) {
$('#deliveryPostcodeEstimator')
.blur(function() {
$('select[name=country] option').filter(function(index) {
if ($(this).text() == $('#deliveryPostcodeEstimator').val().toUpperCase()) {
var result = true;
} else {
// return the last item in the dropdown list
}
console.log(result);
return result;
}).prop('selected', true);
var thisForm = $(this).closest("form");
//thisForm.submit();
})
.keyup(function() {
$(this).val($(this).val().toUpperCase());
})
}
In the code above, the user enters the outcode of a postcode. If there is a match (onblur) then the item is selected. I can’t for the life of me work out how to set a default to the last item (Rest of the UK). I can set the default selected item, but I’d like it to default back to Rest of the UK if there is no match.
Thanks
Why not set the selected option to
Rest of UKprior to conducting the filtering. Then let the filtering if appropriate overwrite the default selection.Example: http://jsfiddle.net/kxuMC/1/