We launched new forums in March 2019—join us there. In a hurry for help with your website? Get Help Now!
    • 21417
    • 486 Posts
    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.]
      Web design Adelaide
      http://gocreate.com.au
      • 17301
      • 932 Posts
      You could set the disabled attribute on the submit button if Australia or another value which triggers the state select is selected. Then remove it when a value is entered
        ■ email: [email protected] | ■ website: https://alienbuild.uk

        The greatest compliment you can give back to us, is to spend a few seconds leaving a rating at our trustpilot: https://uk.trustpilot.com/review/alienbuild.uk about the service we provided. We always drop mention of services offered by businesses we've worked with in the past to those of interest.
        • 21417
        • 486 Posts
        Great idea LK but I don't know how to / what code to do that. Do you?
          Web design Adelaide
          http://gocreate.com.au
          • 17301
          • 932 Posts
          I haven't tested it and you'll need to modify the id's and classes to fit but:


          $("#first-select").change(function(){
            // Get the selected option
            var country = $(this).find("option:selected").attr("class");
            // Log the selected option in console
            console.log(country);
          
            // Cache the state select box
            var $showStates = $('#states');
          
            switch (country){
              case "show-states":
                // Show the state box if an option with the class 'show-states' is selected
                $showStates.slideToggle('slow');
                break;
            }
          
          });
            ■ email: [email protected] | ■ website: https://alienbuild.uk

            The greatest compliment you can give back to us, is to spend a few seconds leaving a rating at our trustpilot: https://uk.trustpilot.com/review/alienbuild.uk about the service we provided. We always drop mention of services offered by businesses we've worked with in the past to those of interest.
            • 21417
            • 486 Posts
            Thanks so much LK, I would like to play with this.
            This may sound like a silly question... but how do I attach it to the input button with the code below? What do I need to change on the button?
            <input class="sender" type="submit" value="Subscribe" title="Subscribe" tabindex="50" /> 
              Web design Adelaide
              http://gocreate.com.au
              • 17301
              • 932 Posts
              Sorry i forgot to include that in the code. I'm on my mobile so I can't check at the moment but I belive it's $('.sender').prop('disabled', true);

              Let me know and I'll write it up later when I get at a pc if you're still struggling.
                ■ email: [email protected] | ■ website: https://alienbuild.uk

                The greatest compliment you can give back to us, is to spend a few seconds leaving a rating at our trustpilot: https://uk.trustpilot.com/review/alienbuild.uk about the service we provided. We always drop mention of services offered by businesses we've worked with in the past to those of interest.
                • 17301
                • 932 Posts
                You'll also need a statement to reply enable the button if a value is selected from the state select. Should be able to use the same logic as above just modified for the different id
                  ■ email: [email protected] | ■ website: https://alienbuild.uk

                  The greatest compliment you can give back to us, is to spend a few seconds leaving a rating at our trustpilot: https://uk.trustpilot.com/review/alienbuild.uk about the service we provided. We always drop mention of services offered by businesses we've worked with in the past to those of interest.
                  • 21417
                  • 486 Posts
                  No worries.... hehe. Ok, yep I am a little lost with how to do it and then the extra statement you are taking about (I am a css'er wink
                  That would be great if possible, no rush
                    Web design Adelaide
                    http://gocreate.com.au