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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 9, 20262026-06-09T13:21:14+00:00 2026-06-09T13:21:14+00:00

here is the scenario: There is a questioner that includes 3 questions and each

  • 0

here is the scenario: There is a questioner that includes 3 questions and each question has 4 multiple answers. User will select an answer to each question and these data is stored in a hidden form in labels, i.e.

<label id=q1>A</label>
<label id=q2>C</label>
<label id=q3>D</label>

Now in case the device is connected to the internet these data can easily be submitted but in case the device has no internet, I need to find a way to store the label data on user’s device and then next time there is a connection, the application to have a submit button which will submit all the stored data (every time the questioner is answered).

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-06-09T13:21:15+00:00Added an answer on June 9, 2026 at 1:21 pm

    What I would do is saving the data in localStorage (although this link points to Phonegap Docs, localStorage is a Html5 feature, quite useful) and periodically calling a function that would check if there’s something to send.

    So, to check the network connection availability:

    function isOnline(){
        try{
            var status = navigator.network.connection.type;
            var val = (status != 'none' && status != 'unknown');
            return val;
        }catch(err){ console.error('isOnline(): '+err); return false; }
    }
    

    Include these lines of code to add some functionality to localStorage, as it just allow to save strings, but with these two functions it will be capable to store JSON data too:

    Storage.prototype.setObject = function(key, value) { 
        this.setItem(key, JSON.stringify(value)); 
    }
    Storage.prototype.getObject = function(key) { 
        var value = this.getItem(key);
        return value && JSON.parse(value); 
    }
    

    In your form submit handler, just check if there is connection. If there’s not, save the data to be sent:

    if(isOnline()){
        // do stuff
    }else{
        var data = // The data to be sent
        var toBeSent = localStorage.getObject('toBeSent') || [];
        toBeSent.push(data);    // It's better to store the data in an array, in case there's more than a questioner to be sent
        localStorage.setObject('toBeSent', toBeSent);
    }
    

    After that write a function that checks and sends the data:

    function sendPending(){
        var toBeSent = localStorage.getObject('toBeSent') || [];
        var data;
        for(var i in toBeSent){
            data = toBeSent[i];
    
            // send data
        }
        // Remove the list
        localStorage.removeItem('toBeSent');
    }
    

    Finally, to execute the function periodically:

    setInterval(sendPending, 60000);  // The system will check every minute if there's something to send
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Scenario: There are multiple C structs, each of which contains a function pointer to
Ok here's the scenario: we have 1 database that has a table we'd like
Here's the scenario: I am writing a program that will run inside a Telit
Here's a problem scenario: I've got a C++ object that includes a Cleanup() virtual
There are many errors here in SO, but this scenario I think its different.
So here's the scenario, I'm building a theme that would display sub category of
Here the scenario : A method is called each minute by a timer. This
Here is the scenario. I have an file outside of my Grails application that
So here's the scenario. I've got a script that runs some tests. I need
Is there an annotation to declare that a certain method will not be included

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.