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

162
Views
how to find html files based on user input and dropdownlist

I am planning to create a search engine for local html files in local server to search for html files by name and choose a folder from the list.

the main idea is to find .html files based on user input and he/she also must choose a folder from the list here is a code that has dropdown list, search box and submit button it now works fine on main folder but I need it to search in listed folders only

function redirect(){
    var url=document.getElementById('test').value
    window.location = url+".html"
}

function handleKeyUp(event) {
    if (event.keyCode === 13) { //13 is enter keycode
      redirect();
    }
}
<select id="selectid">
    <option j-link="" value="" selected="">please choose folder</option>
    <option j-link="./1/" value="">folder1</option>
    <option j-link="./2/" value="">folder2</option>
    <option j-link="./3/" value="">folder3</option>
</select>

<input id="test" type="text" autofocus onkeyup="handleKeyUp(event)">
<button type="button" onclick="redirect()">Submit</button>

about 4 years ago · Juan Pablo Isaza
2 answers
Answer question

0

  • I will suggest you use a form and listen to a submit event on it rather than using event.keyCode === 13.
  • You have to pass the correct value for each of the options of the select field instead of value="" or else every option you select will return an empty string.

Try this

document.addEventListener('DOMContentLoaded', function(){
    let form   = document.getElementById('search-form');
    let folder = form.querySelector('[name="folder"]');
    let file   = form.querySelector('[name="file"]');

    form.addEventListener('submit', event => {
        event.preventDefault();

        let folderValue = folder.value.trim();
        let fileValue   = file.value.trim();

        if( folderValue && fileValue ){
             window.location = folderValue+'/'+fileValue+".html" 
        }else{
            file.focus();
        }
    })
})
<form id="search-form">
    <select name="folder">
        <option j-link="" value="" selected>please choose folder</option>
        <option j-link="./1/" value="folder1">folder1</option>
        <option j-link="./2/" value="folder2">folder2</option>
        <option j-link="./3/" value="folder3">folder3</option>
    </select>

    <input type="text" name="file" autofocus>
    <button type="submit">Submit</button>
</form>

about 4 years ago · Juan Pablo Isaza Report

0

You need for that approach a backend. For example PHP, nodejs, phyton. For two reasons:

1.) First to generate the entire opportunity (folders) automatically

2.) To search in the selected server

From your frontend you will pass the location to the backend. And the backend can search and give a resonse to the frontend.

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!