0

So I have this program that whenever the expiration date is exactly the same date as today the background of the <div> will change it color. But right now, the background color change only when my condition is == and when I try to use>= or <= the background color does not change. Also the background color change even the expiration date is not the same as the date today

Here is my javascript:

<script type="text/javascript">

var $today = date("m/d/Y");
var $expired = $passport_expiration;

function myDIV() {
  if ($today == $expired) {
    document.getElementById("myDiv").style.backgroundColor="#ff4d4d";
  }
}
</script>

Here's my HTML:

<div class="col-md-6" id="myDiv">
    <div class="alert" role="alert"><span class="glyphicon glyphicon-book" aria-hidden="true"></span>&nbsp;&nbsp;Passport <?php echo "<strong><a href=\"view_latest_passport.php?id=$id\"> $passport</a> /&nbsp; Passport Expiration Date:</strong> $passport_expiration"; ?></div>
</div>

How I get the $today and passport_expiration, it is in my query

Thank you in advance

Kode.Error404
  • 563
  • 5
  • 23
aron pascua
  • 101
  • 1
  • 9

1 Answers1

0
<div class="col-md-6" id="myDiv">
    <div class="alert" role="alert">
    <span class="glyphicon glyphicon-book" aria-hidden="true"></span>&nbsp;&nbsp;
    Passport <?php echo "<strong><a href=\"view_latest_passport.php?id=$id\"> $passport</a> /&nbsp; 
    Passport Expiration Date:</strong> $passport_expiration"; ?></div>
    <input type="hidden" id="passport_expire_date" name="passport_expire_date" value="<?php echo $passport_expiration; ?>">
     <?php $date = date("m/d/Y "); ?>
     <input type="hidden" id="today_date" name="today_date" value="<?php echo $date; ?>">
</div>

u need to assign that values in input field then only, it will be validated in javascript

<script type="text/javascript">

var today = document.getElementById("today_date");
var expired = document.getElementById("passport_expire_date");

function myDIV() {
  if ($today == $expired) {
    document.getElementById("myDiv").style.backgroundColor="#ff4d4d";
  }
}
</script>
Kalaivani M
  • 1,200
  • 14
  • 28