The Web Design Group

... Making the Web accessible to all.

Welcome Guest ( Log In | Register )

 
Reply to this topicStart new topic
> Check if DATE is passed, How can I check if a date within an input value is passed?
Robert773
post Jul 21 2017, 06:12 AM
Post #1





Group: Members
Posts: 1
Joined: 21-July 17
Member No.: 26,465



Hello, this is Robert and I've got some troubles with JavaScript.

I got an <input value="DATE" hidden=""> (which is hidden).
The only thing I want to ask you is: I want to check if the date in <input value=""> is passed. If it is passed I want to change the background color of the container in CSS. Unfortunately I don't know how to do this.

If it's possible to convert the input value e.G value="03/08/2017" automatically to <div class="tag">AUG</div> and <div class="monat">03</div>. So if I update the value through my CMS I want to update the 03/AUG also. So if value="28/12/2017" the result schould be automatically <div class="tag">DEZ</div> and <div class="monat">28</div>

I hope you could follow me. Cheers.



<!-- begin snippet: js hide: false console: true babel: false -->

<!-- language: lang-js -->

<script type="text/javascript">
$("tr").sort(function(a,b){
String date = new Date($(a).find("input").val()).getDate();
if(date < Date.now){
//Change the background color of eventscontainer to red
}
}).appendTo("tbody")
</script>

<!-- language: lang-html -->

<table border="0">
<thead>

</thead>
<tbody>

<!-- SPALTE 1-->

<tr>

<td>
<input value="03/08/2017">
<div class="tag">AUG&nbsp;</div>
<br/>
<div class="monat">03&nbsp;</div>
</td>
<td class="info">
<div class="information">

<img src="musik1.png" width="20em" height="20em" style="margin-bottom: 1%;">
Charts, EDM, HipHop

<br/> <img src="location.png" width="20em" height="20em" style="margin-bottom: 1%;">
Wien, Österreich<br/>

<img src="dj.png" width="25em" height="25em" style="margin-bottom: 1%;">
Club Ypsilon

</div>

</td>
<td class="tag-ausgeschrieben"><br/>
fr&nbsp;&nbsp;</td>

</tr>
</tbody>
</table>

<!-- end snippet -->

User is offlinePM
Go to the top of the page
Toggle Multi-post QuotingQuote Post
CharlesEF
post Jul 21 2017, 02:30 PM
Post #2


Programming Fanatic
********

Group: Members
Posts: 1,981
Joined: 27-April 13
From: Edinburg, Texas
Member No.: 19,088



Seems you might be using jQuery in your code, I don't do jQuery. Also, it seems your date format is 'dd/mm/yyyy' which the Javascript Date command will not accept (maybe some browsers do?). But before I get into all that maybe this format will help you, if both dates are in the same format.
CODE
  if("03/08/2017" < "04/08/2017")
  {
   alert("Date is less.");
  }
The above code will alert the message.
On the other hand since you have div's for month and day you might be better off parsing the dates into Date objects, like this:
CODE
  var pdate = "03/08/2017";
  var parray = pdate.split("/");
  var pd = new Date(parray[2], parray[1], parray[0]);
  alert(pd.getMonth());
  alert(pd.getDate());
  alert(pd.getFullYear());
The above code will alert 3 times, showing month - day - year. You will also need to parse the other date as well. After both dates are converted into date objects you can compare like this:
CODE
  if(pd < cd)
  {
   alert("Date is less.");
  }
User is offlinePM
Go to the top of the page
Toggle Multi-post QuotingQuote Post

Reply to this topicStart new topic
2 User(s) are reading this topic (2 Guests and 0 Anonymous Users)
0 Members:

 



- Lo-Fi Version Time is now: 19th March 2024 - 02:54 AM