0

I have the following code on Codepen.

http://codepen.io/anon/pen/pnyvG

My aim is to allow users to input their own dates and then it gets outputted into another element in a more readable format e.g. Type date or choose date, and then display date in a paragraph tag in the following format "Wednesday 7th August".

Also, I have a few additional pieces of functionality I require, which would be awesome if someone could give me some direction;

  • Once the date is outputted into paragraphs for each input, output the number of nights in between the two dates into another element
  • Be able to use the same date picker for both inputs. similar to the behaviour used on the following form; http://www.hipmunk.com/hotels-search

It would great if you guys could help me out.

Thanks in advance,

B

2 Answers 2

1

Look here to get you started:

$(function() {
    $( "#datepicker" ).datepicker({
        altField: "#alternate",
        altFormat: "DD, d MM, yy"
    });
});
Sign up to request clarification or add additional context in comments.

1 Comment

Thanks, but this seems to be limited to input fields. When I change the alternative field to a paragraph is does not work
0

You can catch the select event of the datepicker, and display the output in your p tag:

$(function() {
    $('#datepicker').datepicker( {
        onSelect: function(date) {
            // Format and display the date in a p tag
            $('#yourptag').html( $.datepicker.formatDate('dd M yy', date) );
        }
    });
});

For finding the date difference, you can refer to: Find difference between two dates picked from jQuery datepicker

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.