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

305
Visualizações
Datalist: Get a text value (Entered) wasn't in list

Please advise. Your help would be greatly appreciated. I have a datalist provided, I need to get and display a text value when a user selected or entered.

For sample code below: when user selected any country, it works fine. But I need to handle when a user enter a country that is NOT in the list (for example: "Canada"), I need to display: "Canada" is not in the country list yet.

<body>      
Please Select Country: 
<input type="text" list="countries" name="countryName" id="countryId" />      
<datalist id="countries">      
    <option value="India">India</option>      
    <option value="United States"></option>      
    <option value="United Kingdom"></option>      
    <option value="China"></option>      
    <option value="Nepal"></option>      
    <option value="Afghanistan"></option>      
    <option value="Iceland"></option>      
    <option value="Indonesia"></option>      
    <option value="Iraq"></option>      
    <option value="Ireland"></option>      
    <option value="Israel"></option>      
    <option value="Italy"></option>      
    <option value="Poland"></option>      
</datalist>      
</body>

I have tried (a code below) to enter a value not in the list (e.g: Canada), it always empty when display:

$("#countryId").on("change", function () {
    //var result = $(this).val();
    var country = document.getElementById('countryId').value
    alert( country + " is not in the country list yet." );
}});
 

Thank you very much in advantage.

about 4 years ago · Santiago Gelvez
1 Respostas
Responde à pergunta

0

I retried and the document.getElementById('countryId').value actually was working!!
I got the text input (not in the datalist) displayed !.... I didn't know what I missed before..... but it works now.

about 4 years ago · Santiago Gelvez 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