That's an interesting idea LK, thanks for the suggestion.
In the state select box I have added a value of N/A to the select an option row.
<option selected="selected" value="N/A"> -- select an option -- </option>
That does work in that if Australia is selected, the State select box is shown and a user can select state as I was hoping for
If any other country selected, the State select box is hidden - and in the email report it says N/A - which is not so bad.
I am thinking this is not quite the nicest way to do it because I have to make a hidden select box required and give a 'dummy' value so it sends. It also wouldn't stand up if the client decided they wanted the states of 2 or more countries (which is likely at some stage), but with just Australian states it is the closest thing I have to working.
I am still hoping for a solution where Australian states don't have to be required unless Australia is selected - I wish the javascript version worked as that shows a lot of promise:
$('#selectHider-stateAU').hide();
$('#country').bind('change', function (e) {
if( $('#country').val() == 'AU') {
//$('#state-au').attr('eform','Australian State::1');
//vs
$("#state-au").data("eform", "Australian State::1");
$('#selectHider-stateAU').slideToggle('fast');
}
else {
//$('#state-au').removeAttr('eform');
//vs
$("#state-au").removeData("eform");
$('#selectHider-stateAU').hide();
}
}).trigger('change');
I guess another option would be to add the javascript to the submit button to check if Australia is selected as the country and if so to make the Australian state field required but I don't know how to implement that.
[ed. note: nickf08 last edited this post 6 years, 11 months ago.]