Empresas
Empleos
  • Sobre nosotros
  • Soluciones
    • Publicación de vacantes
      Publica tu vacante y recibe candidatos calificados en 48h.
    • Evaluación de candidatos
      500+ pruebas técnicas y psicológicas, más anti-fraude.
    • Headhunting
      Búsqueda ejecutiva a la medida de principio a fin.
    • Nómina + EOR
      Dispersión de nómina y EOR en más de 15 países de LATAM.
  • Precios
  • Empleos

0

94
Vistas
select option for select element from data attribute using JQuery

I want to select option for select element from value in select element data attribute..

<?php 
$selectval = 0;
?>

<select data-value="<?=$selectval?>">
<option value="1">yes</option>
<option value="0">no</option>
</select>

what I did in JQuery:

$('select').val($('select').data('value'));

but it is not working, I am still getting the first option as selected

I also tried to print the value directly to value attribute also not working

<?php 
$selectval = 0;
?>

<select value="<?=$selectval?>">
<option value="1">yes</option>
<option value="0">no</option>
</select>

NOTE: I have more than one select element in the DOM and I want all of them to get values from data-attribute

about 4 years ago · Juan Pablo Isaza
Responde la pregunta
Encuentra empleos remotos

¡Descubre la nueva forma de encontrar empleo!

Top de empleos
Top categorías de empleo
Empresas
Publicar vacante Precios Comercial
Legal
Términos y condiciones Política de privacidad
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomiéndame algunas ofertas
Necesito ayuda