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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 12, 20262026-06-12T17:57:31+00:00 2026-06-12T17:57:31+00:00

I have a form with a input box that I want to auto-complete with

  • 0

I have a form with a input box that I want to auto-complete with values from a IndexedDb objectStore, this works with two over positioned input boxes. I works fine with a simple array but I want to put it to work with the values from a objectStore.
For this I have to put the values available out of the transaction so I can loop through them in the auto-complete function.

1- How can I get the results out of the transaction into a object available in the rest of the code?

2- Is my loop syntax ok “results.value.name.length” (name is my objectStore index) to work with the resultant object?

Getting the IndexedDb objects through a cursor:

var results = [];

var openDbRequest = indexedDB.open(DB_NAME);

openDbRequest.onsuccess = function (e) {
    var db = e.target.result;
    var tran2 = db.transaction("store");
    tran2.objectStore("store").openCursor().onsuccess = function(e) {
        var cursor = e.target.result;
        if (cursor) {
            results = cursor;
            cursor.continue();  
        };
    };                                      
};

The autocomplete function

var auto = "";
var auto_disp = "";

function getName(results) {
    var input = document.forms['myform'].name.value;
    var len = input.length;
    if (input.length) {
        for (i=0; i<results.value.name.length; i++){            
            if (results.value.name[i].substr(0,len).toLowerCase() == input.toLowerCase()){
                auto_disp = input + results.value.name[i].substr(len);
                auto = results.value.name[i];
                break;
            }
        }
    }
document.forms['myform'].auto_name.value = auto_disp;
}

function setName() {
 document.forms['myform'].name.value = auto;
 hideAuto();
}

function hideAuto() {
 document.forms['myform'].auto_name.value = "";
}

The HTML form:

<div style="position: absolute; top: 0; left: 0; width: 200px; z-index: 1;">
 <input type="text" name="name" style="background-color: #fff; border: 1px solid #999; width: 200px; padding: 2px" disabled />
</div>

<div style="position: absolute; top: 0; left: 0; width: 200px; z-index: 2;">
 <input autocomplete="off" type="text" name="auto_name" style="background: none; color:#39f; border: 1px solid #999; width: 200px; padding: 2px" onfocus="getName()"onkeyup="getName()" onkeydown="if (event.keyCode == 13) {setName();};"/>
</div>

UPDATE: Tried a different chaining, now I get the cursor but there’s something wrong with the loop, I’m not getting the auto-completion.

openDbRequest.onsuccess = function (e) {
    var db = e.target.result;

    var tran2 = db.transaction("store");
    tran2.objectStore("store").openCursor().onsuccess = function(e) {

        var cursor = e.target.result;
        if (cursor) { 
            var input = document.forms['myform'].country.value; //the inputted value
            var len = input.length;
            if (input.length) {
                for (i=0; i<cursor.length; i++){            
                    if (cursor.value.nome[i].substr(0,len).toLowerCase() == input.toLowerCase()){
                        auto_disp = input + cursor.value.nome[i].substr(len);
                        auto = cursor.value.nome[i];
                        break;                              
                    }
                }   
            }
            document.forms['myform'].auto_name.value = auto_disp;
            cursor.continue();  
        }   
    };
};
  • 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-12T17:57:32+00:00Added an answer on June 12, 2026 at 5:57 pm

    If you want to use it outside the transaction scope, just add it to a variable

    var results = [];
    var openDbRequest = indexedDB.open(DB_NAME);
    openDbRequest.onsuccess = function (e) {
        var db = e.target.result;
        var tran2 = db.transaction("store");
        tran2.objectStore("store").openCursor().onsuccess = function(e) {
             var cursor = e.target.result;
             if (cursor) {
                  results.push(cursor.value) 
                  cursor.continue();
             };
        };
    }; 
    

    After this you van iterate over the results object, and the transaction scope will close once all data is retrieved.

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

Sidebar

Related Questions

I have a form in a .html files where input/select box looks like this
I have developed an e-commerce site. For user form input box, i want to
I have in input box that can only contain numerical values (with use of
So I have an input form that I want to use to update a
I have an input box that that is part of a form . depending
I have a form with a style input box and a <a> tag that
I have a <form> that looks like this: <form> <input type=text name=name id=name /><span
i have one form which have some input box and some select box. i
I have... a dynamic populated select box several input boxes a submit button form
This seems like a must have form input for a mobile ui framework, but

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.