Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8831861
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 14, 20262026-06-14T08:24:18+00:00 2026-06-14T08:24:18+00:00

I’m making a simple registration system, where the user must first select the state,

  • 0

I’m making a simple registration system, where the user must first select the state, before selecting the city. So far so good. I also created a function to specify two states that have cities with different shipping.

The user selects the state where he lives, then input the town. If he select the specific state, the he chooses the city from a SELECT FIELD. So far so good too.

I want to clear the input #cidade every time I change the select #estado.

My javascript so far:

$(function() {
    $('#estado').change(function() {
        var typeSelected = $(this).val();
        if (typeSelected == "0") {
            $('#cidade').hide();
            $('#santacatarina').hide();
            $('#parana').hide();
        }
        else if (typeSelected == "Santa Catarina") {
            $('#cidade').hide();
            $('#santacatarina').show();
            $('#parana').hide();
        }
        else if (typeSelected == "Paraná") {
            $('#cidade').hide();
            $('#santacatarina').hide();
            $('#parana').show();
        }
        else{
            $('#cidade').show();
            $('#santacatarina').hide();
            $('#parana').hide();
        }
    }).change();
});
$(function() {
    $('#cidadesSC').change(function() {
        var typeSelected = $(this).val();
        if (typeSelected == "0") {
            $('#outraCidadeSC').hide();
        }
        else if (typeSelected == "Outra Cidade") {
            $('#outraCidadeSC').show();
        }
        else{
            $('#outraCidadeSC').hide();
        }
    }).change();
});
$(function() {
    $('#cidadesPR').change(function() {
        var typeSelected = $(this).val();
        if (typeSelected == "0") {
            $('#outraCidadePR').hide();
        }
        else if (typeSelected == "Outra Cidade") {
            $('#outraCidadePR').show();
        }
        else{
            $('#outraCidadePR').hide();
        }
    }).change();
});
//here is the function I've been trying to do the clear of #cidade
$(function() {
    $('#estado').change(function() {
        $('#cidade').clear();
    });
});

The HTML for it. It is a bit longer:

<select id="estado" name="estado">
    <option value="0">Selecione</option>
    <option value="Acre">Acre</option>
    <option value="Alagoas">Alagoas</option>
    <option value="Amazonas">Amazonas</option>
    <option value="Amapá">Amapá</option>
    <option value="Bahia">Bahia</option>
    <option value="Ceará">Ceará</option>
    <option value="Distrito Federal">Distrito Federal</option>
    <option value="Espírito Santo">Espírito Santo</option>
    <option value="Goiás">Goiás</option>
    <option value="Maranhão">Maranhão</option>
    <option value="Minas Gerais">Minas Gerais</option>
    <option value="Mato Grosso">Mato Grosso</option>
    <option value="Mato Grosso do Sul">Mato Grosso do Sul</option>
    <option value="Pará">Pará</option>
    <option value="Paraíba">Paraíba</option>
    <option value="Paraná">Paraná</option>
    <option value="Pernambuco">Pernambuco</option>
    <option value="Piauí">Piauí</option>
    <option value="Rio de Janeiro">Rio de Janeiro</option>
    <option value="Rio Grande do Norte">Rio Grande do Norte</option>
    <option value="Rio Grande do Sul">Rio Grande do Sul</option>
    <option value="Rondonia">Rondonia</option>
    <option value="Roraima">Roraima</option>
    <option value="Santa Catarina">Santa Catarina</option>
    <option value="Sergipe">Sergipe</option>
    <option value="São Paulo">São Paulo</option>
    <option value="Tocantins">Tocantins</option>
</select>
<input id="cidade" type="text" style="display:none; border:2px solid blue;">

<div style="clear:both;"></div>

<div id="santacatarina" style="display:none;">
    <select id="cidadesSC" name="cidadesSC">
        <option value="0">Selecione</option>
        <option value="Araquari">Araquaria</option>
        <option value="Balneário Camboriú">Balneário Camboriú</option>
        <option value="Barra Velha">Barra Velha</option>
        <option value="Biguaçu">Biguaçu</option>
        <option value="Blumenau">Blumenau</option>
        <option value="Bombinhas">Bombinhas</option>
        <option value="Brusque">Brusque</option>
        <option value="Camboriú">Camboriú</option>
        <option value="Florianópolis">Florianópolis</option>
        <option value="Garuva">Garuva</option>
        <option value="Gaspar">Gaspar</option>
        <option value="Governador Celso Ramos">Governador Celso Ramos</option>
        <option value="Ilhota">Ilhota</option>
        <option value="Indaial">Indaial</option>
        <option value="Itajaí">Itajaí</option>
        <option value="Itapema">Itapema</option>
        <option value="Itapoá">Itapoá</option>
        <option value="Jaraguá do Sul">Jaraguá do Sul</option>
        <option value="Joinville">Joinville</option>
        <option value="Luiz Alves">Luiz Alves</option>
        <option value="Navegantes">Navegantes</option>
        <option value="Palhoça">Palhoça</option>
        <option value="Penha">Penha</option>
        <option value="Piçarras">Piçarras</option>
        <option value="Pomerode">Pomerode</option>
        <option value="Porto Belo">Porto Belo</option>
        <option value="São Francisco do Sul">São Francisco do Sul</option>
        <option value="São José">São José</option>
        <option value="Schroeder">Schroeder</option>
        <option value="Tijucas">Tijucas</option>
        <option value="Timbó">Timbó</option>
        <option value="Outra Cidade">Outra Cidade</option>
    </select>
    <p style="float:right;">Santa Catarina possuí cidades com <a href="#">Frete Grátis</a></p>
    <input id="outraCidadeSC" type="text" style="display:none; border:2px solid red;">
</div>

<div id="parana" style="display:none;">
    <select id="cidadesPR" name="cidadesPR">
        <option value="0">Selecione</option>
        <option value="Curitiba">Curitiba</option>
        <option value="Outra Cidade">Outra Cidade</option>
    </select>
    <p style="float:right;">Paraná possuí cidades com <a href="#">Frete Grátis</a></p>
    <input id="outraCidadePR" type="text" style="display:none; border:2px solid green;">
</div>

What can I do?

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-14T08:24:19+00:00Added an answer on June 14, 2026 at 8:24 am
    $(function() {
    $('#estado').change(function() {
        $('#cidade').val('');  // empty the #cidade
        var typeSelected = $(this).val();
        if (typeSelected == "0") {
            $('#cidade').hide();
            $('#santacatarina').hide();
            $('#parana').hide();
        }
        else if (typeSelected == "Santa Catarina") {
            $('#cidade').hide();
            $('#santacatarina').show();
            $('#parana').hide();
        }
        else if (typeSelected == "Paraná") {
            $('#cidade').hide();
            $('#santacatarina').hide();
            $('#parana').show();
        }
        else{
            $('#cidade').show();
            $('#santacatarina').hide();
            $('#parana').hide();
        }
    }).change();
    });
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I'm making a simple page using Google Maps API 3. My first. One marker
I have a string like this: La Torre Eiffel paragonata all&#8217;Everest What PHP function
link Im having trouble converting the html entites into html characters, (&# 8217;) i
I have just tried to save a simple *.rtf file with some websites and
I am doing a simple coin flipping experiment for class that involves flipping a
We're building an app, our first using Rails 3, and we're having to build
I'm parsing an RSS feed that has an &#8217; in it. SimpleXML turns this
I'm trying to select an H1 element which is the second-child in its group
Seemingly simple, but I cannot find anything relevant on the web. What is the
I'm working with an upstream system that sometimes sends me text destined for HTML/XML

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.