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

93
Views
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
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!