Expiring Today—Celebrate National IT Professionals Day with 3 months of free Premium Membership. Use Code ITDAY17

x
?
Solved

Jquery search input value for current year

Posted on 2013-06-01
3
Medium Priority
?
379 Views
Last Modified: 2013-06-01
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
0
Comment
Question by:maccaj51
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 2
3 Comments
 
LVL 58

Accepted Solution

by:
Julian Hansen earned 2000 total points
ID: 39212667
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>
<html>
<head>
<title>Test</title>
<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) {
    e.preventDefault();
    var dt = new Date($('#current-date').val());
    var nw = new Date();
    nw.getDate();
    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');
    }
  });
});
</script>
<style type="text/css">
</style>
</head>
<body>
<div><a href="#">Click to Test</a></div>
Input here <input type="text" id="current-date" />
<div id="result">
</div>
</body>
</html>

Open in new window

0
 

Author Closing Comment

by:maccaj51
ID: 39212687
Perfect - Many thanks
0
 
LVL 58

Expert Comment

by:Julian Hansen
ID: 39212811
You are welcome - thanks for the points.
0

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.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Introduction If you're like most people, you have occasionally made a typographical error when you're entering information into an online form.  And to your consternation, the browser remembers the error, and offers to autocomplete your future entr…
In this blog, we’ll look at how improvements to Percona XtraDB Cluster improved IST performance.
The viewer will learn how to dynamically set the form action using jQuery.
The viewer will learn the basics of jQuery, including how to invoke it on a web page. Reference your jQuery libraries: (CODE) Include your new external js/jQuery file: (CODE) Write your first lines of code to setup your site for jQuery.: (CODE)
Suggested Courses

718 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question