Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 7757033
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 1, 20262026-06-01T12:58:37+00:00 2026-06-01T12:58:37+00:00

i having a problem with a global method called returnDayNumber. If i call the

  • 0

i having a problem with a global method called returnDayNumber. If i call the function within my java script it works fine. but when i made a button to call the function it said: “self.returnDayNumber is not a function” (thought var self=this might solve issue).
here is my code:

 /*
     * Global data
     * used to centralize user data to be used in graphs
     */
    var userModel = new userHealthModel();
    userModel.createUsers();

    userModel.addUser();


    var newChart = new NewHighCharts();

    returnDayNumber = function(month, day)
    {
        if(month==1)
        {
            return day;
        }
        else if(month==2)
        {
            return(31+day);
        }
        else if(month==3)
        {
            return(60+day);
        }
        else if(month==4)
        {
            return (91+day);
        }
        else if(month==5)
        {
            return(121+day);
        }
        else if(month==6)
        {
            return(152+day);
        }
        else if(month==7)
        {
            return(182+day);
        }
        else if(month==8)
        {
            return(213+day);
        }
        else if(month==9)
        {
            return(244+day);
        }
        else if(month==10)
        {
            return(274+day);
        }
        else if(month==11)
        {
            return(305+day);
        }
        else if(month==12)
        {
            return(335+day);
        }           
    }
    saveThis = function()
    {
        var self = this;
        alert("your about to save!")
        newChart.destroyChart();
        newChart= new NewHighCharts();
        var numberOfUsers = userModel.users().length;
        var users = userModel.users();
        var weights = userModel.getWeights();
        var dates = userModel.getDates();
        var dataArray = [];
        var xAndY = []
        var singleDate;
        var name;
        for(var i=0;i<numberOfUsers;i++)
        {
            name = users[i].name;
            xAndY = [];
            for(var x=0;x<dates.length-1;x++)
            {

                //extract month
                var month = ([dates[i][x]].toString()).substring(0,2);
                //extract day
                day = parseInt(([dates[i][x]].toString()).substring(3,5));
                //add the day number and weight of users to an array of x and y coordinates
                xAndY.push([self.returnDayNumber(month,day),weights[i][x]])
            }
            newChart.addNewSeries(name,xAndY);
        }       
     ///!!!!This works!!!///
     this.saveThis()//!!!

    }
    ko.applyBindings(userModel);

i made a KO user model but i dont think its relevant. and here is my HTML, note its KO syntax but it works.

<button  data-bind="click: saveThis">Save</button>

im probably making a simple mistake or something is out of scope. Im a java script beginner so sorry for the simple question. Many thanks to any helpful programmers!

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-01T12:58:39+00:00Added an answer on June 1, 2026 at 12:58 pm

    Move var self = this; outside of your saveThis function not inside, that way self is in the right scope.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I'm having problem restricting a query in mdx, using except function at where clause.
I am attempting to pass function scope to a callback method. The problem I
I'm having problem with global variable in PHP. I have mysqli config file which
Having a problem understanding what I will call a variable scope question for lack
I'm having a problem with global variables in JavaScript. What I tried doing was
Having problem with the middle Div not expanding to the width http://acs.graphicsmayhem.com/images/middiv.jpg Ok, how
I'm having problem when running my Windows Forms program. In the program, I have
I'm having problem with Rails plugin attachment_fu . On every upload, I get validation
i'm having problem to deal with charset in ruby on rails app, specificially in
I am having problem in getting reference of Ajax control extender using $find() or

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.