7

on the mobile version of my site I am using input type=date instead of a jquery datepicker to allow for use of the devices inbuilt datepicker as it's generally much quicker and easier to use.

I am trying to detect when 1 date field has a value inputted/changed, to then update the min date attribute of a second datefield, and , submit the form using ajax.

I cannot correctly detect the input or change.

$('#mob-gig-date-gteq').blur(function() {
    var date = $("#mob-gig-date-gteq").val();
    console.log(date)
    $(this).closest("form").submit();
});

(Using .change yields the same results)

If I select a date here nothing happens. On the computer if I select a date, press enter on one of the inputs (day/month/year) and THEN change the date again, the code fires. On mobile nothing happens at all.

How can I detect the input change on a date field?

Thanks.

1 Answer 1

17

Try the jquery .change method. Blur will only fire when the input loses focus.

$('#mob-gig-date-gteq').change(function() {
    var date = $(this).val();
    console.log(date, 'change')
});

Code pen tested in chrome

Sign up to request clarification or add additional context in comments.

6 Comments

Ok, this is strange. As I mentioned in the question I have already tried using .change. The thing is, your example works fine, but the same thing on my site doesn't.
@Rob Have you checked the input tag has and id mob-gig-date-gteq and jQuery is added to the page?
Yes. If I press enter on any of the inputs (Day/Month/Year) everything starts to work.
Dammit. It was a stupid error on my part. Everything is working now. What a waste of 2 hours!!!
@Rob sometimes you just need to talk it though with someone even if they are just there to smile and nod. Happens to me all the time!
|

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.