473,387 Members | 1,859 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,387 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 1404
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...
0
by: taylorcarr | last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...

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.