0

I have a family tree website and want to show all events in our family on the current date (Month and Day). So, if today's April 3rd, I want to show all events in our family that occurred on April 3rd.

I've played with creating a table and hiding rows, etc. but the table's too big and it's taking too long. So, I've decided to create a separate .htm file for each day of the year (i.e., todayinhistory-0101.htm, todayinhistory-0102.htm, etc.).

I have a button which, when clicked, is to get the current date in MMDD format and then open the correct file.

I have the script to get the correct filename using the current date in MMDD format, but I can't figure out how to call it and make it work.

Right now, my button looks like this:

<button onclick="location='GetTodayInHistoryFilename()'">

GetTodayInHistoryFilename() is a function I know works. I just can't get the button format right to call it.

Obviously, I'm a novice and would appreciate anyone's help.

In case you're interested, here's GetTodayInHistoryFilename() - which is loaded in the page's header section:

<script type='text/javascript'>
 function GetTodayInHistoryFilename()
     {
         var Today = new Date();
         var TodayMonth = Today.getMonth()+1;
         var TodayDay = Today.getDate();
         if (TodayMonth < 10) { TodayMonth = '0' + String(TodayMonth); } else { TodayMonth = String(TodayMonth); }
         if (TodayDay < 10) { TodayDay = '0' + String(TodayDay); } else { TodayDay = String(TodayDay); }
         return 'todayinhistory-' + TodayMonth + TodayDay + '.htm';
     }
</script>

Thanks in advance.

Michael
  • 11
  • 3

1 Answers1

0

I'm not 100% sure this is what you're trying to do but I think you want the button click to navigate to another HTML page in which case - you're not far off:

<button onclick="window.location=GetTodayInHistoryFilename()">

Explanation: You're setting the location property of the window object (your browser's top level frame, in this case) to (a new url). You've defined this using your function which is fine. The only mistake you made was to include the function in quotes. This meant that function name was treated as a literal text string rather than an executable function.

You may or may not need to specify window. (the global object) in window.location. I wasn't sure myself but it's nicely answered here: window.location versus just location

Andrew Chart
  • 623
  • 6
  • 10