title: jQuery Selectbox to Textbox
body: <p>Before changing country</p>
  
  <p><a href="https://i.stack.imgur.com/SfL6r.png" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/SfL6r.png" alt="enter image description here"></a></p>
  
  <p>After changing country</p>
  
  <p><a href="https://i.stack.imgur.com/Nc46M.png" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/Nc46M.png" alt="enter image description here"></a></p>
  
  <p>As you saw on the pictures i want to replace selectbox with textbox for city and town depends on changing country. (I need selectbox only in my country. For other countries i need textbox.)</p>
  
  <p>If the client change country i'm replacing selectbox to textbox. It is ok. But if the client want to back old country selection I need to reload city and town as selectbox. But it is not working</p>
  
  <p>What should i do ?</p>
  
  <p>Here is my jquery file.</p>
  
  <pre><code>&lt;script type="text/javascript"&gt;
      $(document).ready(function(){
          var city = $('#city').html();
          var town = $('#town').html();
  
          $('#country').change(function(city, town){
              var country = $(this).val();
              if(country != 'Türkiye')
              {
                  $('#city').replaceWith('&lt;input class="form-control" type="text" name="city" id="city"&gt;');
                  $('#town').replaceWith('&lt;input class="form-control" type="text" name="town" id="town"&gt;');
              }
              else
              {
                  $('#city').replaceWith(city);
                  $('#town').replaceWith(town);
              }
          });
      });
  &lt;/script&gt;
  </code></pre>
  
  <p><strong>UPDATE:</strong> I'm almost done. (I used @Rhumborl 's method.)</p>
  
  <p>But there is a problem. Town depends on city selection. Normally when city changes i'm loading new towns. But in this issue. It is not working.</p>
  
  <p>In this event code fails.</p>
  
  <ol>
  <li>I changed country.</li>
  <li>I turned back Turkey.</li>
  <li>I changed city to Ankara, new towns are loading from Ankara.</li>
  <li>When i changed any other country and turn back to Turkey. I can see city as Ankara. But towns are not Ankara's. Towns are from origin City Nevşehir.</li>
  </ol>
  
  <p>Here is screenshot</p>
  
  <p><a href="https://i.stack.imgur.com/P8Nzf.png" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/P8Nzf.png" alt="enter image description here"></a></p>
  
  <p>This is conflict.</p>