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

273
Visualizações
i try to make a form in NodeJs for searching a user in mongodb by telephone number using query routing, i don't know why this not working?

What is the wrong with this code? I got the exactly mobile number on the console but not on query routing on /search_user?mob ?

<input type="tel" name="message" id="mobile_input" value="">
                  <!--getting mobile no. from the input tag -->
                  <script type="text/javascript" defer>
                    e => {
                     e.preventDefault();
                     var mobInput = document.querySelector('#mobile_input');//get the input tag.
                     var moby = mobInput.value;//get mobile no. 
                     console.log(moby);//be sure from the variable mob 
                     mobInput.value='';//reset the input tag.
                     return moby;
                    }
                  </script>
                   <!-- query routing on /search_user?mob -->                 
                 
                   <a href="/search_user?mob=moby" class="border-shadow">Search</a>
about 4 years ago · Juan Pablo Isaza
1 Respostas
Responde à pergunta

0

I tried something like this and this seems to work.

    <form>
        <input type="tel" name="message" id="mobile_input">
        <button type="submit" onclick="handleSearch(document.getElementById('mobile_input').value)">Search</button>
    </form>
                  <!--getting mobile no. from the input tag -->
                  <script type="text/javascript" defer>

               

                    // const handleChange = (value) => {
                    //     var mobInput = value
                    //     console.log(mobInput)
                    //    
                    // }

                    const handleSearch = (input) => {
                        var searchValue = input;
                        console.log("This is the search value " + searchValue)
                        var url = '/search_user?mob=' + searchValue;
                        console.log(url)
                        window.location.href = url;
                    }
                    
                  </script>

Explanation: I changed the a href element for a button element. Every time the button is clicked (onclick) the function handleSearch is called. This function takes as input the value of the input element with ID "mobile_input". Of course, you can clean up the function a bit more. After merging the url basis ('/search_user?mob=') with the input value (searchValue), the handleSearch function should redirect to the url (calling window.location.href). This last one you can of course change for the correct call to the server. Hope this helps.

Side note: you will see that there is a commented-out handleChange function. You could call this function in the input element to keep track of your changes in the console. this function is called using onChange, just like you use onClick with the search button. For more info:https://www.w3schools.com/jsref/event_onchange.asp

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