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

91
Views
how to return string with select box with select option selected as per a given variable

I using Datatable library to show a table in wordpress custom plugin where I need to return selectbox input. The select box option should display the option as it is saved in database but it is showing the first option always.

How to code the same thing in js when the select input is returned for a column in datatable. I have tried the following way:

columns: [{
       
{
            'data': null,
            'render': function (data, type, row, meta) {
                 
                
            return '<select class="selectpicker" name="pm" id="pm-' + row.mls + '"><option value="Tafolla">Tafolla</option><option value="Lucy">Lucy</option></select>';

            }
         },
}]
about 4 years ago · Santiago Gelvez
1 answers
Answer question

0

Well first get the JS value that is selected then based off return call the php value in a separate call not inlineHTML . Try not overcomplicate cross language calls ...

document.getElementById('my-select').addEventListener('change', function() {
  console.log('You selected: ', this.value);

 //Call PHP values based on selection e.g
 if(this.value == 2) 
 {
   var text = " <?php echo ($row['status'] == 'AR')?'selected='selected':''; ?>";

 }


});
<select id="my-select">
  <option value="1">One</option>
  <option value="2">Two</option>
  <option value="3">Three</option>
</select>

The other way of doing it is in plain php with HTML select

<select name="formGender">
   <option value="">Select...</option>
   <option value="M">Male</option>
   <option value="F">Female</option>
 </select>

//PHP
<?php

 if(isset($_POST['formSubmit']) )
  {
   $varGender = $_POST['formGender'];         
  }

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