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

139
Vistas
Change background color in an input from ajax

I have the following code, where when selecting a value in the select returns a date to put in the input.

$('#title1').change(function(){
  var data = {"title1":$('#title1').val(),
  "title":$("#title").val()};
  $.ajax({
    type:"POST",
    url:"./atribdatt1",
    dataType:"Json",
    data:data,
    success:function(callback){
      var data_array = callback;
      artdat = data_array
      $("#vali1").html(artdat);
      document.getElementById('vali1').value = artdat;
    }
  });
});
<script src="https://cdnjs.cloudflare.com/ajax/libs/jquery/3.3.1/jquery.min.js"></script>

<div class="form-group">
  <label for="title1" class="col-sm-4 control-label">NOME VISITANTE</label>
  <div class="col-sm-8">
    <select name="title1" class="form-control" id="title1">
      <option></option>
      <?php
      $sql = "SELECT * FROM raddb.Utente WHERE ativo = '1' AND codigo NOT IN ('701', '723') ORDER BY nome ASC";
      $qr = mysqli_query($conn, $sql);
      while($ln = mysqli_fetch_assoc($qr)){
      echo '<option value="'.$ln['codigo'].'">'.$ln['nome'].'</option>';
      }
      ?>
    </select>
  </div>
</div>
<div class="form-group">
  <input type="date" name="vali1" class="form-control" id="vali1" readonly="true">
</div>

I intended that if the returned date is less than two days from the current date, put the input in red. This way it always returns only the date but does not change the color of the input. Can you help?

about 4 years ago · Juan Pablo Isaza
1 Respuestas
Responde la pregunta

0

So, for access styles from JavaScript DOM elements have a style prop. The names of styles in javascript is camelCase keys in style. https://api.jquery.com/css/
Usage:

const element = $("selector") // or on vanilla document.querySelector('selector')
// ...
element.css('background', 'red') // vanilla - element.style.background = 'red'
about 4 years ago · Juan Pablo Isaza 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