title: HTML/Javascript/PHP Country and State List
body: <p>I have a script that is getting the country the user selects and then puts the corresponding states in the state  box.</p>
  
  <p>Here is my Javascript code in the head:</p>
  
  <pre><code>&lt;script type="text/javascript" src="jquery-1.9.1.min.js"&gt;
  &lt;/script&gt;
  
  &lt;script type="text/javascript"&gt;
  $(document).ready(function () {
  $("#theselect").change(function() {
  var option = $(this).val();
          $.get("select.php", {select:option},function(data){
              $("#theresult").html(data).hide().fadeIn(1000);
          });
      });
  });
  &lt;/script&gt;
  </code></pre>
  
  <p>Here is the HTML code in the body:</p>
  
  <pre><code>&lt;select name="theselect" id="theselect"&gt;
  &lt;option value=""&gt;Select&lt;/option&gt;
  &lt;option value="submit_ind"&gt;Submit Individual Need&lt;/option&gt;
  &lt;option value="submit_org"&gt;Submit Organization Need&lt;/option&gt;
  &lt;option value="missionary"&gt;Submit Missionary Need&lt;/option&gt;
  </code></pre>
  
  <p>Here is the select.php script that is giving what information is to be displayed when each option is selected:</p>
  
  <pre><code>echo "&lt;script type= 'text/javascript' src = 'http://www.1511project.com/countries.js'&gt;&lt;/script&gt;
  ";
  
  
  ***The other options are usually here but due to character restraints I had to delete to rest of it.  So I do have an original If statement and 2 other elseif statement***    
  
  elseif($_GET['select'] == 'missionary') {
  
  echo "&lt;script&gt;print_country('country');&lt;/script&gt;";
  
  ?&gt;
  &lt;script&gt;
  
  function limitText(limitField, limitCount, limitNum) {
      if (limitField.value.length &gt; limitNum) {
          limitField.value = limitField.value.substring(0, limitNum);
      } else {
          limitCount.value = limitNum - limitField.value.length;
      }
  }
  
  function validateForm()
  {
  var x=document.forms["myForm"]["firstname"].value;
  if (x==null || x=="")
    {
    alert("First name must be filled out");
    return false;
    }
  
  var r=document.forms["myForm"]["titleofneed"].value;
  if (r==null || r=="")
    {
    alert("Title of need must be filled out");
    return false;
    }
  
  var s=document.forms["myForm"]["country"].value;
  if (s==null || s=="")
    {
    alert("Country must be filled out");
    return false;
    }
  
  
  var u=document.forms["myForm"]["phone"].value;
  
  var b=document.forms["myForm"]["email"].value;
  if ((b==null || b=="") &amp;&amp; (u==null || u==""))
    {
    alert("Email or Phone must be provided for contact information.");
    return false;
    }
  
  var c=document.forms["myForm"]["city"].value;
  if (c==null || c=="")
    {
    alert("City must be filled out");
    return false;
    }
  
  var d=document.forms["myForm"]["state"].value;
  if (d==null || d=="")
    {
    alert("State must be filled out");
    return false;
    }
  
  var h=document.forms["myForm"]["recurring"].value;
  if (h==null || h=="")
    {
    alert("Recurring need must be filled out");
    return false;
    }
  
  var j=document.forms["myForm"]["typeofneed"].value;
  if (j==null || j=="")
    {
    alert("Type of need must be filled out");
    return false;
    }
  
  }
  &lt;/script&gt;
  
  &lt;p&gt;Please enter the information below for the CONTACT PERSON of the need you are submitting.&lt;br /&gt;&lt;br /&gt;&lt;/p&gt;
  &lt;form action="processneedmiss.php" name="myForm" method="post" onsubmit="return validateForm();"&gt;
  &lt;p&gt;First Name: &lt;input type="text" name="firstname" /&gt;&lt;/p&gt;
  &lt;p&gt;Phone #: &lt;input type="text" name="phone" /&gt; &lt;img src='http://www.aotees.com/images/questionMarkIcon_SMALL.jpg' alt='Must provide phone number OR email.  Providing both is recommended.' title='Must provide phone number OR email.  Providing both is recommended.' height='15' width='15'&gt;&lt;/p&gt;
  &lt;p&gt;Email: &lt;input type="text" name="email" /&gt; &lt;img src='http://www.aotees.com/images/questionMarkIcon_SMALL.jpg' alt='Must provide phone number OR email.  Providing both is recommended.' title='Must provide phone number OR email.  Providing both is recommended.' height='15' width='15'&gt;&lt;/p&gt;
  
  
  
  
  &lt;p&gt;Country: &lt;select onchange="print_state('state',this.selectedIndex);" id="country" name = "country"&gt;&lt;/select&gt;&lt;/p&gt;
  
  &lt;p&gt;District/State: &lt;select name ="state" id = "state"&gt;&lt;/select&gt;&lt;/p&gt;
  
  
  
  
  
  &lt;p&gt;City: &lt;input type="text" name="city" /&gt;&lt;/p&gt;
  &lt;p&gt;Title of Need: &lt;input type="text" name="titleofneed" /&gt; &lt;img src='http://www.aotees.com/images/questionMarkIcon_SMALL.jpg' alt='Type a short title to organize your needs.' title='Type a short title to organize your needs.' height='15' width='15'&gt;&lt;/p&gt;
  &lt;p&gt;Type of Need: &lt;select name="typeofneed"&gt; &lt;option&gt;&lt;/option&gt;&lt;option&gt;Supplies&lt;/option&gt;&lt;option&gt;Lawn Care&lt;/option&gt; &lt;option&gt;Heavy Lifting&lt;/option&gt;&lt;option&gt;Event Volunteering&lt;/option&gt;&lt;option&gt;Home Repair&lt;/option&gt; &lt;option&gt;Clean Up&lt;/option&gt; &lt;option&gt;Other&lt;/option&gt;&lt;/select&gt;&lt;/p&gt;
  &lt;p&gt;Recurring Need:
  &lt;select name='recurring' size='1'&gt;
  &lt;option value=''&gt;&lt;/option&gt;
  &lt;option&gt;No&lt;/option&gt;
  &lt;option&gt;Yes&lt;/option&gt;
  &lt;/select&gt; &lt;img src='http://www.aotees.com/images/questionMarkIcon_SMALL.jpg' alt='If need happens on a regular basis, select Yes' title='If need happens on a regular basis, select Yes.' height='15' width='15'&gt;
  &lt;/p&gt;
  &lt;p&gt;
  How many people are needed: &lt;input type="number" name="howmanypeople" /&gt; &lt;img src='http://www.aotees.com/images/questionMarkIcon_SMALL.jpg' alt='If you want the need to be taken down after a certain number of people sign up for the need, enter that number here. If you only want 1 person leave this blank.' title='If you want the need to be taken down after a certain number of people sign up for the need, enter that number here. If you only want 1 person leave this blank.' height='15' width='15'&gt; 
  &lt;/p&gt;
  &lt;p&gt;Expiration Date: (If no expiration date leave blank.)
  &lt;br&gt;
  Month: 
          &lt;select name='month' size='1'&gt;
      &lt;option value='0'&gt;&lt;/option&gt;
      &lt;option value='1'&gt;1&lt;/option&gt;
      &lt;option value='2'&gt;2&lt;/option&gt;
      &lt;option value='3'&gt;3&lt;/option&gt;
      &lt;option value='4'&gt;4&lt;/option&gt;
      &lt;option value='5'&gt;5&lt;/option&gt;
      &lt;option value='6'&gt;6&lt;/option&gt;
      &lt;option value='7'&gt;7&lt;/option&gt;
      &lt;option value='8'&gt;8&lt;/option&gt;
      &lt;option value='9'&gt;9&lt;/option&gt;
      &lt;option value='10'&gt;10&lt;/option&gt;
  &lt;option value='11'&gt;11&lt;/option&gt;
  &lt;option value='12'&gt;12&lt;/option&gt;
  &lt;/select&gt;
    Day:
  &lt;select name='day' size='1'&gt;
      &lt;option value='0'&gt;&lt;/option&gt;
      &lt;option value='1'&gt;1&lt;/option&gt;
      &lt;option value='2'&gt;2&lt;/option&gt;
      &lt;option value='3'&gt;3&lt;/option&gt;
      &lt;option value='4'&gt;4&lt;/option&gt;
      &lt;option value='5'&gt;5&lt;/option&gt;
      &lt;option value='6'&gt;6&lt;/option&gt;
      &lt;option value='7'&gt;7&lt;/option&gt;
      &lt;option value='8'&gt;8&lt;/option&gt;
      &lt;option value='9'&gt;9&lt;/option&gt;
      &lt;option value='10'&gt;10&lt;/option&gt;
  &lt;option value='11'&gt;11&lt;/option&gt;
  &lt;option value='12'&gt;12&lt;/option&gt;
  &lt;option value='13'&gt;13&lt;/option&gt;
  &lt;option value='14'&gt;14&lt;/option&gt;
  &lt;option value='15'&gt;15&lt;/option&gt;
  &lt;option value='16'&gt;16&lt;/option&gt;
  &lt;option value='17'&gt;17&lt;/option&gt;
  &lt;option value='18'&gt;18&lt;/option&gt;
  &lt;option value='19'&gt;19&lt;/option&gt;
  &lt;option value='20'&gt;20&lt;/option&gt;
  &lt;option value='21'&gt;21&lt;/option&gt;
  &lt;option value='22'&gt;22&lt;/option&gt;
  &lt;option value='23'&gt;23&lt;/option&gt;
  &lt;option value='24'&gt;24&lt;/option&gt;
  &lt;option value='25'&gt;25&lt;/option&gt;
  &lt;option value='26'&gt;26&lt;/option&gt;
  &lt;option value='27'&gt;27&lt;/option&gt;
  &lt;option value='28'&gt;28&lt;/option&gt;
  &lt;option value='29'&gt;29&lt;/option&gt;
  &lt;option value='30'&gt;30&lt;/option&gt;
  &lt;option value='31'&gt;31&lt;/option&gt;
  &lt;/select&gt;
    Year:
  &lt;select name='year' size='1'&gt;
      &lt;option value='0'&gt;&lt;/option&gt;
      &lt;option value='2012'&gt;2012&lt;/option&gt;
      &lt;option value='2013'&gt;2013&lt;/option&gt;
      &lt;option value='2014'&gt;2014&lt;/option&gt;
      &lt;option value='2015'&gt;2015&lt;/option&gt;
      &lt;option value='2016'&gt;2016&lt;/option&gt;
      &lt;option value='2017'&gt;2017&lt;/option&gt;
      &lt;option value='2018'&gt;2018&lt;/option&gt;
      &lt;option value='2019'&gt;2019&lt;/option&gt;
      &lt;option value='2020'&gt;2020&lt;/option&gt;
      &lt;option value='2021'&gt;2021&lt;/option&gt;
      &lt;option value='2022'&gt;2022&lt;/option&gt;
      &lt;option value='2023'&gt;2023&lt;/option&gt;
      &lt;option value='2024'&gt;2024&lt;/option&gt;
      &lt;option value='2025'&gt;2025&lt;/option&gt;
      &lt;option value='2026'&gt;2026&lt;/option&gt;
      &lt;option value='2027'&gt;2027&lt;/option&gt;
      &lt;option value='2028'&gt;2028&lt;/option&gt;
  &lt;/select&gt;
  &lt;/p&gt;
  &lt;p&gt;Description of Need: &lt;br&gt;(Do not include sensitive information you don't want others seeing on the website.)&lt;br /&gt;&lt;textarea name="description" onKeyDown="limitText(this.form.description,this.form.countdown,850);" 
  onKeyUp="limitText(this.form.description,this.form.countdown,850);" style="margin: 2px; width: 494px; height: 164px;"&gt;&lt;/textarea&gt;&lt;br&gt;&lt;font size="1"&gt;(Maximum characters: 850)&lt;br&gt;
  You have &lt;input readonly type="text" name="countdown" size="4" value="850"&gt; characters left.&lt;/font&gt;&lt;/p&gt;
  &lt;p&gt;&lt;input type="submit" value="Submit" /&gt;&lt;/p&gt;
  &lt;/form&gt;
  &lt;?php
  }
  ?&gt;
  </code></pre>
  
  <p>The issue I'm having is that when people choose the "missionary" option the first time, it won't display the missionary form.  But if I choose another form first then choose the missionary option, it will show and work fine.  Or if I choose another form first, then the missionary option it will work.  But it doesn't work if I choose "missionary" first.</p>
  
  <p>I've tracked down the source of the problem to this piece of code in the "missionary" form:</p>
  
  <pre><code>&lt;script&gt;print_country('country');&lt;/script&gt;
  </code></pre>
  
  <p>If that code is anywhere in the form, the form won't pull up the first time.</p>
  
  <p>Can anyone help?</p>