Business
Jobs
  • About Us
  • Solutions
    • Job Postings
      Post your job and receive qualified candidates in 48h.
    • Candidate Assessments
      500+ technical and psychological tests, plus anti-fraud.
    • Headhunting
      Tailor-made executive search from start to finish.
    • Payroll + EOR
      Payroll dispersal and EOR across 15+ LATAM countries.
  • Pricing
  • Jobs

0

271
Views
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 answers
Answer question

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 Report
Answer question
Find remote jobs

Discover the new way to find a job!

Top jobs
Top job categories
Business
Post vacancy Pricing Sales
Legal
Terms and conditions Privacy policy
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Show me some job opportunities
There's an error!