Empresas
Empregos
  • Sobre nós
  • Soluções
    • Publicação de vagas
      Publique sua vaga e receba candidatos qualificados em 48h.
    • Avaliações de candidatos
      Mais de 500 testes técnicos e psicológicos, mais anti-fraude.
    • Headhunting
      Busca executiva personalizada do início ao fim.
    • Folha de Pagamento + EOR
      Dispersão de folha e EOR em mais de 15 países da LATAM.
  • Preços
  • Empregos

0

134
Visualizações
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 Respostas
Responde à pergunta

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 Relatório
Responde à pergunta
Encontrar trabalhos remotos

Descubra a nova forma de encontrar um emprego!

melhores empregos
Principais categorias de trabalho
Empresas
Postar vaga Preços Comercial
Jurídico
Termos e Condições Política de privacidade
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomende algumas ofertas para mim
Preciso de ajuda