Conditional State / Province based upon Country

mbajames 30 Nov, 2010
Hi all,

I am sure I am doing something simply wrong, but I am trying to make a conditional form where a list of states appears when a person uses a radio button to signify they are from the US, a list of provinces when from Canada, and a text field area when they specify other. I can do it for a simple 1 --ie, states when select US, but after that nothing happens on the others.

If you will, please look at my code and point me in the correct direction:

<?php
$script = "
  window.addEvent('domready', function() {
    var selectDiv = function() {
      if ( $('UnitedStates').checked == true ) {
        $('boxform1_states').setStyle('display', 'block');
	$('boxform1_provinces').setStyle('display', 'none');
	$('boxform1_other').setStyle('display', 'none');
   }
      if ( $('Canada').checked == true ) {
        $('boxform1_states').setStyle('display', 'none');
	$('boxform1_provinces').setStyle('display', 'block');
	$('boxform1_other').setStyle('display', 'none');
		
}
	  if ( $('Other').checked == true ) {
        $('boxform1_states').setStyle('display', 'none');
	$('boxform1_provinces').setStyle('display', 'none');
	$('boxform1_other').setStyle('display', 'block');
}	  
	  	     	  
    };
    $('UnitedStates').addEvent('change', selectDiv);
    $('Canada').addEvent('change', selectDiv);
    $('Other').addEvent('change', selectDiv);
	
  });
";
$doc =& JFactory::getDocument();
$doc->addScriptDeclaration($script);
?>


Thanks. At the same time, if anyone needs the html list for Canadian provinces and US states/territories, I will add them in my next response.
GreyHead 30 Nov, 2010
Hi mbajames,

The code looks fine to me. Please post a link to the form so we can take a quick look.

Bob
This topic is locked and no more replies can be posted.