Empresas
Empregos
  • Sobre nós
  • Soluções
    • Publicação de vagas
      Publique sua vaga e receba candidatos qualificados em 48h.
    • Avaliações de candidatos
      Mais de 500 testes técnicos e psicológicos, mais anti-fraude.
    • Headhunting
      Busca executiva personalizada do início ao fim.
    • Folha de Pagamento + EOR
      Dispersão de folha e EOR em mais de 15 países da LATAM.
  • Preços
  • Empregos

0

162
Visualizações
Dynamically filling two fields depending on a dropdown value

I have a database server name recommendation list coming from the backend, where "driverName" and "connectionURL" for that driver should auto-populate once the user picks a server. I know it's possible to accomplish it with javascript, but I'm new to the language. Could someone please assist me?


                        <div class="form-group">
                            <form:label path="databaseServer">Database Server:</form:label>
                            <form:select path="databaseServer" class="form-control">
                                <form:option value="None" label="Please Select a Database Server"/>
                                <form:options items="${command.databaseServerMap}" />
                            </form:select>

                        </div>
                        <div class="form-group">
                            <form:label path="driverName">Driver Name:</form:label>
                            <form:input path="driverName" class="form-control"  readonly="true"/>

                        </div>
                        <div class="form-group">
                            <form:label path="connectionURL">connection URL:</form:label>
                            <form:input path="connectionURL" class="form-control" readonly="true"/>
                        </div>

These are the maps I'm working with on the backend.


  public Map<String, String> getDatabaseServerMap() {
        Map<String, String> driverList = new LinkedHashMap<>();
        driverList.put("MySQL", "MySQL");
        driverList.put("Postgres", "Postgres");
        return driverList;
    }


  [1]: https://i.stack.imgur.com/HKUWd.png
about 4 years ago · Juan Pablo Isaza
1 Respostas
Responde à pergunta

0

This javaScript code was effective.



<script>
        $(function () {
            $('.selectDatabase').change(function(){
       //         console.log( $(this).val() );
                const driverName=$('.driverName');
                const  connectionURL  = $('.connectionURL');

                if($(this).val()==='MySQL'){
                    driverName.val('com.microsoft.sqlserver.jdbc.SQLServerDriver');
                    connectionURL.val('jdbc:sqlserver://localhost:1433;databaseName=database');
                    driverName.attr('readonly',true);
                    connectionURL.attr('readonly',true);

                }else if($(this).val()==='Other'){
                    driverName.val('');
                    connectionURL.val('');
                    driverName.attr('readonly',false);
                    connectionURL.attr('readonly',false);

                }else{
                    driverName.val('');
                    connectionURL.val('');
                    driverName.attr('readonly',true);
                    connectionURL.attr('readonly',true);
                }

            });

        });


    </script>


<div class="form-group">
                            <form:label path="databaseServer">Database Server:</form:label>
                            <form:select path="databaseServer" class="form-control selectDatabase">
                                <form:option value="None" label="Please Select a Database Server"/>
                                <form:options items="${command.databaseServerMap}" />
                            </form:select>

                        </div>
                        <div class="form-group">
                            <form:label path="driverName">Driver Name:</form:label>
                            <form:input path="driverName" class="form-control driverName"  readonly="true"/>
                        </div>
about 4 years ago · Juan Pablo Isaza Relatório
Responde à pergunta
Encontrar trabalhos remotos

Descubra a nova forma de encontrar um emprego!

melhores empregos
Principais categorias de trabalho
Empresas
Postar vaga Preços Comercial
Jurídico
Termos e Condições Política de privacidade
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomende algumas ofertas para mim
Preciso de ajuda