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

93
Vistas
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 Respuestas
Responde la pregunta

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 Denunciar
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