Jump to content


suportetecnicojunior

Member Since 14/04/2010
Offline Last Active 29/10/2010, 20:23
-----

Posts I've Made

In Topic: Menu Drop Down Dependente

22/04/2010, 11:07

RESOLVIDO!!!

In Topic: Campo Select Automático

14/04/2010, 20:12

Boa tarde, tudo bem?

Eu recomendo utilizar AJAX, mas se você não quiser, utilize o seguinte código:

<html>
    <head>
        <title>Select</title>
        <meta content="http-equiv" type="text/html; charset=utf-8" />
        <script type="text/javascript">
        function changeCity() {
            clearSelect();

            if(document.getElementById('estados').selectedIndex == 1) {
                var option = document.createElement('option');
                option.setAttribute('value', 'florianópolis');
                option.appendChild(document.createTextNode('Florianópolis'));
                document.getElementById('cidades').appendChild(option);
            }
            else if(document.getElementById('estados').selectedIndex == 2) {
                var option = document.createElement('option');
                option.setAttribute('value', 'porto alegre');
                option.appendChild(document.createTextNode('Porto Alegre'));
                document.getElementById('cidades').appendChild(option);
            }
        }

        function clearSelect() {
            document.getElementById('cidades').options.length = 0;

            var option = document.createElement('option');
            option.appendChild(document.createTextNode('Selecione um Estado'));
            document.getElementById('cidades').appendChild(option);
        }
        </script>
    </head>
    <body>
        <h1>Select</h1>
        <form method="post" action="">
            <fieldset>
                <label for="estados">Estado</label>
                <select id="estados" name="estados" onchange="changeCity()">
                    <option>Selecione um Estado</option>
                    <option value="sc">Santa Catarina</option>
                    <option value="rs">Rio Grande do Sul</option>
                </select>
                <label for="cidades">Cidade</label>
                <select id="cidades" name="cidades">
                    <option>Selecione um Estado</option>
                </select>
            </fieldset>
        </form>
    </body>
</html>

Um abraço, tudo de bom.


Como eu adiciono mais um drop???

IPB Skin By Virteq