473,290 Members | 1,957 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,290 software developers and data experts.

next and previous function not defined error am trying to fix it but couldn't please

Expand|Select|Wrap|Line Numbers
  1. <html> <head> <meta charset="utf-8" /> <meta http-equiv="X-UA-Compatible" content="IE=edge"> <title></title> <meta name="viewport" content="width=device-width, initial-scale=1"> <link rel="stylesheet" type="text/css" media="screen" href="https://bytes.com/calender.css" /> <link rel="stylesheet" href="https://cdnjs.cloudflare.com/ajax/libs/font-awesome/4.7.0/css/font-awesome.min.css"> <script src="https://bytes.com/calender.js" type="text/javascript"></script> </head> <body onload="initialise();"> <button onclick="previous();"> <i class="fa fa-angle-down"></i></button> <span id="thismonth"></span> <button onclick="next();"> <i class="fa fa-angle-up"></i></button> </body> <script>
  2. var months = ["January","February","March","April","May","June","July","August","September","October","November","December"];
  3. var currentMonth=0;
  4. var currentYear=0;
  5. var d= new Date();
  6. currentMonth=d.getMonth();
  7. currentYear=d.getFullYear();
  8. var firstdate=months[currentMonth]+ " " + 1 + " " + currentYear;
  9. function initialise(){
  10.         document.getElementById("thismonth").innerHTML=months[currentMonth]+ "  " + currentYear;
  11. function previous(){
  12.     if(currentMonth===0){
  13.  
  14.         currentMonth=11;
  15.         currentYear=currentYear-1;
  16.     }
  17.     else if(currentMonth>0){
  18.         currentMonth=currentMonth-1;
  19.  }
  20.  document.getElementById("thismonth").innerHTML=months[currentMonth]+ "  " + currentYear;
  21. }
  22.  
  23.  
  24. function next(){
  25.     if(currentMonth<11){
  26.  
  27.         currentMonth=currentMonth+1;
  28.     }
  29.     else if(currentMonth === 11){
  30.         currentMonth=0;
  31.         currentYear=currentYear+1;     
  32.     }
  33.     document.getElementById("thismonth").innerHTML=months[currentMonth]+ " " +currentYear;
  34. }
  35. }
  36. </script> </html>
Oct 19 '18 #1
1 1401
gits
5,390 Expert Mod 4TB
have a close look at what you did construct. you are declaring the functions next and previous in the scope of the function initialise - thus they are not available in the window scope from where you want to call them in your onclick-handlers.

a hacky and not the preferred way to fix that could be to just add something like this:

Expand|Select|Wrap|Line Numbers
  1. window.previous = function previous() { ...
which would bind the function to the window scope with the name previous so it could be called as you did.

The better way would be to assign the handler during the initialise-operation (instead of polluting the window scope like in the above example). There are different ways to do it like:

Expand|Select|Wrap|Line Numbers
  1. node.onclick = function() { //code here };
or:

Expand|Select|Wrap|Line Numbers
  1. node.addEventListener('click', function() { //code here }, true || false);
instead of writing the functions like in that pseudo-code above it would be more elegant to declare them before and assign/pass them by name only.
Oct 19 '18 #2

Sign in to post your reply or Sign up for a free account.

Similar topics

3
by: Marcel | last post by:
Hello, I'm working on a search application for my website. The website contains a lot of pictures, and a search should return clickable thumbnails. No problems there. My problem started when I...
6
by: Steve Strik | last post by:
Hi, I'm using access 97 SR2 on win XP and keep getting the Sub or Function not defined error message. The code for the function is in a module called mod_Public and is as follows. Function...
0
by: BCC | last post by:
In 6.0, I had a great little macro that would with ctrl+page down go to the next function header in a .cpp file, and with ctrl+page up would go to the previous function header. Was super...
5
by: utab | last post by:
Dear all, I had some replies on my previous post.But wanted to learn sth. Static member functions of a class can access only the static data members of the same class. So this principle in mind,...
3
by: dekern | last post by:
Good afternoon all, I guess I am missing the benefit of using datasets with Crystal. For years I have written wrapper apps that used the Pull method and I let Crystal do all the sql work. Now...
1
by: Sylaris | last post by:
hi, i have a problem which recursion fits perfectly, however; after working with the base function (which has no errors and works correctly) the recursions return a "function not defined" error in...
1
by: Integra | last post by:
I have developed a VB application with Access running very well except some systems which doesnt installed VB. Created the setup with Innosetup. But its working in some systems eventhough vb not...
6
by: empiresolutions | last post by:
I'm trying to slightly alter the script found here, http://www.adrianhodge.com/web-design/mootools-horizontal-div-slider-121/. What i want to do is make the carousel work on a Next/Previous...
1
by: mattmasters | last post by:
Hi there I am new to this forum so would appreciate any help that is on offer. I am writing some VB in Excel and getting the "Run-Time error '1004'. Application- defined or object-defined...
0
by: Hema Suresh | last post by:
Hi all I am trying to create a database using vb6 and excel I created few controls on the vb form and coded to get the details from the user I code in the way to pass the data which i got from the...
2
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 7 Feb 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:30 (7.30PM). In this month's session, the creator of the excellent VBE...
0
by: DolphinDB | last post by:
The formulas of 101 quantitative trading alphas used by WorldQuant were presented in the paper 101 Formulaic Alphas. However, some formulas are complex, leading to challenges in calculation. Take...
0
by: DolphinDB | last post by:
Tired of spending countless mintues downsampling your data? Look no further! In this article, you’ll learn how to efficiently downsample 6.48 billion high-frequency records to 61 million...
0
by: Aftab Ahmad | last post by:
Hello Experts! I have written a code in MS Access for a cmd called "WhatsApp Message" to open WhatsApp using that very code but the problem is that it gives a popup message everytime I clicked on...
0
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 6 Mar 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). In this month's session, we are pleased to welcome back...
0
by: marcoviolo | last post by:
Dear all, I would like to implement on my worksheet an vlookup dynamic , that consider a change of pivot excel via win32com, from an external excel (without open it) and save the new file into a...
1
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 6 Mar 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). In this month's session, we are pleased to welcome back...
0
by: jfyes | last post by:
As a hardware engineer, after seeing that CEIWEI recently released a new tool for Modbus RTU Over TCP/UDP filtering and monitoring, I actively went to its official website to take a look. It turned...
1
by: PapaRatzi | last post by:
Hello, I am teaching myself MS Access forms design and Visual Basic. I've created a table to capture a list of Top 30 singles and forms to capture new entries. The final step is a form (unbound)...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.