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 7659773
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 31, 20262026-05-31T13:22:38+00:00 2026-05-31T13:22:38+00:00

I am new to javascript, and can’t find the solution to this. I have

  • 0

I am new to javascript, and can’t find the solution to this.
I have read some of the similar questions, but did not look like the problem was the same as mine.

I call a method from script1 with this code:

 function turnPage(){
    var current = window.now;
    var nextpage = getNextPage(current);
    alert(nextpage);
}

In script2 there is a SQLite etc:

function getNextPage(Pid) {
    db.transaction(function(tx) {
        tx.executeSql('SELECT * FROM Page WHERE Pid=' + Pid, [],
                    function(tx, results) {
            nextp = parseInt(results.rows.item(0).NextPage);
            //alert(nextp);
            return nextp;   
        }, errorCB);
    }, errorCBQuery);
}

if I use the alert-dialog in the called function, the variable nextp is 2.
BUT if I return the variable, it will alert as ‘undefined’.
Also, if I etc make the variable var nextp = 11; over “db.transaction…” and the return-statement at the end of the function, it will return 11 instead of 2.

Is it because the variable is not sent to the inner function in my inception of functions? 🙂

Any ideas of what to do? thanks!

  • 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-05-31T13:22:38+00:00Added an answer on May 31, 2026 at 1:22 pm

    I don’t know how SQLite in javascript works, but I suspect it works asynchronously, so you’re calling alert in turnPage but the transaction is running async and the return value is in another scope anyway. You can try passing a callback function to getNextPage and then instead of returning nextp call the callback with nextp as argument:

    function turnPage(){
        var current = window.now;
        getNextPage(current, function (nextp) { alert(nextp); /* do whatever else you need to do */ });
    }
    
    
    
    function getNextPage(Pid, cb) {
        db.transaction(function(tx) {
            tx.executeSql('SELECT * FROM Page WHERE Pid=' + Pid, [],
                        function(tx, results) {
                nextp = parseInt(results.rows.item(0).NextPage);
                cb(nextp);   
            }, errorCB);
        }, errorCBQuery);
    }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

im new at javascript and i can get this slider to work but not
i have a javascript method that takes a date: convert(new Date(02/20/2010); how can i
New to javascript, but I'm sure this is easy. Unfortunately, most of the google
I'm new to JavaScript and I can't figure out why this code isn't working.
With the new File API in Javascript you can read files in Javascript to
I know JavaScript can open a link in a new window but is it
I am new to JavaScript OOP. Can you please explain the difference between the
Well, I'm completely new to JavaScript. Can you please tell me what type of
How can i concatenate var names to declare new vars in javascript?: var foo
I can bind a jquery event to this element like: <script type=text/javascript> $('#new_key').ready(function() {

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.