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

259
Visualizações
get a data-attribute (data-phone) value from the selected datalist option

how to get a data-attribute (like:- data-phone ) value from the selected datalist option which is selected; It send me just value not data attribute.

i want to set data-phone of input from data-phone of datalist > option

How can I set this? Help

Html:

     <input type="text" name="patirnt_name" id="patirnt_name" list="patient_list" onfocus="getAllPatients()" value="" data-phone="">
         <datalist id="patient_list">

         </datalist>

JQuery:

function getAllPatients() {
            let url = "{{ route('get-all-patient-ajax') }}";
            let list = $('#patient_list');

            let html = '';
            $.ajax({
                url: url,
                type: "GET",
                success: function(res) {
                    let data = res.patients;

                    $.each(data, function(index, value) {
                        html +=
                            `<option value="${value.F_name}" data-phone="${value.phone}" >${value.F_name}</option >`;
                    });

                    list.html(html);

                },
                error: function(error) {
                    console.log(error);
                }
            })
        }
about 4 years ago · Juan Pablo Isaza
1 Respostas
Responde à pergunta

0

As far as I understand, when you list.html(html) all the options are displayed in the DOM without the data-phone="${value.phone}" that you set in the each loop. You could try this:

$.each(data, function(index, value) {
    $('<option/>', { 
          value : value.F_name,
          data-phone : value.phone
    }).text(value.F_name).appendTo(list);
});
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