Skip to main content
himab5254998
Participant
May 6, 2018
Question

i want a js to validate current date with entered date and to replace a image

  • May 6, 2018
  • 2 replies
  • 1248 views

hai pls help me out of this

    This topic has been closed for replies.

    2 replies

    sinious
    Legend
    May 15, 2018

    Regardless of the application, JS has a Date object that can perform that comparison very simple using vanilla JS. It would be something like (ES5):

    // create date to test and todays date

    var testDate = new Date( '12/25/2018' ); // MM/DD/YYYY

    var todaysDate = new Date(); // today, per the computer that's running the JS engine

    // compare

    if ( testDate.setHours(0,0,0,0) == todaysDate(0,0,0,0) ) {

         // true, today

    } else {

         // false, not today

    }

    As for the image, if it's on the web or Acrobat or something else, we'll need to know. On the web the vanilla ES5 way is simply alter the 'src' property of the image, and hopefully give it a class or an ID so you can easily locate it. Plain ES5 e.g.:

    <!-- HTML -->

    <img src="images/mypic.png" id="someImage">

    // JS

    <script type='text/javascript'>

    // wait for window to load

    window.addEventListener( 'load', function() {

         // change image .src attribute via ID

         document.getElementById( 'someImage' ).src = 'images/anotherimage.png';

    });

    </script>

    try67
    Community Expert
    Community Expert
    May 8, 2018

    In what context? A web-page? A PDF file? Something else? You need to provide more details...