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

168
Visualizações
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 Respostas
Responde à pergunta

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 Relatório

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 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