• Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 390
  • Last Modified:

Jquery search input value for current year

Hi Experts,

as the title suggest... I need an if/else script that checks a form field to see whether it contain the current year.

Then runs a different code if it does or doesnt contain it.

Please help!! many thanks in advance
  • 2
1 Solution
Julian HansenCommented:
This will work assuming the date information is entered correctly, you may need to extend to allow for more variance in the date input.

<!doctype html>
<script src="https://ajax.googleapis.com/ajax/libs/jquery/1.7.2/jquery.min.js"></script>
<script type="text/javascript">
$(function() {
  $('a').click(function(e) {
    var dt = new Date($('#current-date').val());
    var nw = new Date();
    if (dt.getYear() == nw.getYear()) {
      $('#result').html('Date is the same as this year');
    else {
      $('#result').html('Date is NOT the same as this year');
<style type="text/css">
<div><a href="#">Click to Test</a></div>
Input here <input type="text" id="current-date" />
<div id="result">

Open in new window

maccaj51Author Commented:
Perfect - Many thanks
Julian HansenCommented:
You are welcome - thanks for the points.
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

Join & Write a Comment

Featured Post

Hire Technology Freelancers with Gigs

Work with freelancers specializing in everything from database administration to programming, who have proven themselves as experts in their field. Hire the best, collaborate easily, pay securely, and get projects done right.

  • 2
Tackle projects and never again get stuck behind a technical roadblock.
Join Now