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

140
Views
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 answers
Answer question

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