Question

var today = new Date();    alert(today);    var parts = today.split(/[-]/);    var month1 =...

var today = new Date();
   alert(today);
   var parts = today.split(/[-]/);

   var month1 = parts[1];
   var year1 = parts[0];
   var date1 = parts[2];

alert(Month1);
   alert(year1);
   alert(date1);

==================

write a simple javascript function to extract the date ,month and year and compare the current selected date with the Todays date and time.

You are required to display a button called 'Today' and clicking on today button should display and highlight todays date and month.

Even if user is accessing 2018 or any random month or year as soon as user clicks on Today button on the calendar it should display current date ,month and year.

============

Language : Javascript.

0 0
Add a comment Improve this question Transcribed image text
Answer #1

<!DOCTYPE html>

<html lang="en">

<head>

    <meta charset="UTF-8">

    <meta name="viewport" content="width=device-width, initial-scale=1.0">

    <meta http-equiv="X-UA-Compatible" content="ie=edge">

    <title>Document</title>

    <link rel="stylesheet" type="text/css" href="https://cdnjs.cloudflare.com/ajax/libs/jquery-datetimepicker/2.5.20/jquery.datetimepicker.css">

    <script src="https://code.jquery.com/jquery-2.2.4.min.js" integrity="sha256-BbhdlvQf/xTY9gja0Dq3HiwQF8LaCRTXxZKRutelT44=" crossorigin="anonymous"></script>

    <script src="https://code.jquery.com/ui/1.12.0/jquery-ui.js" integrity="sha256-0YPKAwZP7Mp3ALMRVB2i8GXeEndvCq3eSl/WsAl1Ryk="   crossorigin="anonymous"></script>

    <script src="https://cdnjs.cloudflare.com/ajax/libs/jquery-datetimepicker/2.5.20/jquery.datetimepicker.full.min.js" ></script>

    <script>


    $( function() {

        //only check

      $( "#mydatepicker" ).datepicker();

    } );

    </script>

</head>

<body>

    <p>Date: <input type="text" id="mydatepicker" onchange="compair()"></p>

    <button onclick="showdate()">Today</button>

    <script>

        function compair(){

            //compair function

            var date = document.getElementById("mydatepicker").value;

            compaireData(new Date(date))

        }

        function showdate(){

            

            var today = new Date();

            var month1 = today.getMonth();

            var date1 = today.getDate();

            alert("Date: "+date1+", Month: "+month1);

            document.getElementById("mydatepicker").value =  today

        }

        function compaireData(date){

            var month = date.getDate();

            var year = date.getFullYear();

            var date = date.getFullYear();

            alert("Date: "+date+", Month: "+month+ " Year: "+ year);

            var today = new Date();

            if(date< today)

                alert("Today is after selected date")

            else

                alert("Selected date is after Today")

        }

       

    </script>

</body>

</html

show the script part

full free to ask in comment

x

Add a comment
Know the answer?
Add Answer to:
var today = new Date();    alert(today);    var parts = today.split(/[-]/);    var month1 =...
Your Answer:

Post as a guest

Your Name:

What's your source?

Earn Coins

Coins can be redeemed for fabulous gifts.

Not the answer you're looking for? Ask your own homework help question. Our experts will answer your question WITHIN MINUTES for Free.
Similar Homework Help Questions
  • Use JavaScript to write the code. Create a website that gets the current system date. After...

    Use JavaScript to write the code. Create a website that gets the current system date. After getting the system date, the variable should be converted to a string and then the parts extracted. You should have day of week, year, month, day of month. Display your results in the body of the website as a paragraph. You can use fucntions like indexof(), etc. to complete this.

  • C++ Programming Step 1. Design a new ADT that implements a class named Date, add 3 private member variables month, day, year along with their appropriate public constructor / getter / setter member fu...

    C++ Programming Step 1. Design a new ADT that implements a class named Date, add 3 private member variables month, day, year along with their appropriate public constructor / getter / setter member functions inside Date.h and Date.cpp. Step 2. Design another ADT that implements a class named Watch, add 3 private member variables hour, minute, second, along with their appropriate public constructor / getter / setter member functions inside Watch.h and Watch.cpp. Step 3. Next, implement the additional SmartWatch...

  • Write a program called RentalRate.java which reads in a date of birth, today’s date and a...

    Write a program called RentalRate.java which reads in a date of birth, today’s date and a male/female designation from the user, and will then determine the basic daily and weekly rates for rental of an economy class car. Rental rate classes are: Best rate (male drivers, age 33–65 and female drivers, age 30-62)--$40.00per day, $200.00 per week Risk rate 1 (female drivers, age 25–29)–Best rate plus $10.00 per day or best rate plus $55.00 per week. Risk rate 2 (male...

  • Using JAVA FX how would I combine the two programs below into one interface that allows...

    Using JAVA FX how would I combine the two programs below into one interface that allows the user to pick which specific program they would like to play. They should be able to choose which one they want to play and then switch between them if necesary. All of this must be done in JAVA FX code Black jack javafx - first game program package application; import java.util.Arrays; import java.util.ArrayList; import javafx.collections.FXCollections; import javafx.collections.ObservableList; import javafx.application.Application; import javafx.geometry.Pos; import javafx.geometry.Insets;...

  • 1. Private data fields: name (of String type, initialized to “Bob”), endurance (of int type, initialized to 4) and happiness (of int type, initialized to 3);

    Language: JAVAPart a: Write a class called Geniegotchi with:1. Private data fields: name (of String type, initialized to “Bob”), endurance (of int type, initialized to 4) and happiness (of int type, initialized to 3);2. Public methods:-void setName(String newName) : renames Genie with newName, printsnewName confirmation to screen;void setName(String newName) : renames Genie with newName, printsnewName confirmation to screen;- intgetEndurance() : returns current endurance;-intgetHappiness() : returns current happiness;-void feed() : this method increases current endurance by 1 if endurance is less...

  • Code is in C# Your instructor would like to thank to Marty Stepp and Hélène Martin...

    Code is in C# Your instructor would like to thank to Marty Stepp and Hélène Martin at the University of Washington, Seattle, who originally wrote this assignment (for their CSE 142, in Java) This program focuses on classes and objects. Turn in two files named Birthday.cs and Date.cs. You will also need the support file Date.dll; it is contained in the starter project for this assignment. The assignment has two parts: a client program that uses Date objects, and a...

  • How can we assess whether a project is a success or a failure? This case presents...

    How can we assess whether a project is a success or a failure? This case presents two phases of a large business transformation project involving the implementation of an ERP system with the aim of creating an integrated company. The case illustrates some of the challenges associated with integration. It also presents the obstacles facing companies that undertake projects involving large information technology projects. Bombardier and Its Environment Joseph-Armand Bombardier was 15 years old when he built his first snowmobile...

ADVERTISEMENT
Free Homework Help App
Download From Google Play
Scan Your Homework
to Get Instant Free Answers
Need Online Homework Help?
Ask a Question
Get Answers For Free
Most questions answered within 3 hours.
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT