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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 13, 20262026-06-13T18:43:12+00:00 2026-06-13T18:43:12+00:00

I have a sentence defined as a list(a string? an array?- I’m not sure

  • 0

I have a sentence defined as a list(a string? an array?- I’m not sure the correct term) that I want returned sequentially as any key is pressed. I’m trying to use .split. Here is the list and function:

var list1 = "This is a test".replace(/\s/g, "\xA0").split("")
function transformTypedChar(charStr) {
    var position = $("#verse1").text().length;
    if (position >= list1.length) return '';
    else return list1[position];
}

Currently, the “T” from the beginning of the list is returned repeatedly, and the rest of the list is ignored. I’m calling the function as follows:

document.getElementById("verse1").onkeypress = function(evt) {
    var val = this.value;
    evt = evt || window.event;

     // Ensure we only handle printable keys, excluding enter and space
    var charCode = typeof evt.which == "number" ? evt.which : evt.keyCode;
    if (charCode && charCode > 32) {
        var keyChar = String.fromCharCode(charCode);

           // Transform typed character
        var mappedChar = transformTypedChar(keyChar);

        var start, end;
        if (typeof this.selectionStart == "number" && typeof this.selectionEnd ==   
   "number") {
            // Non-IE browsers and IE 9
            start = this.selectionStart;
            end = this.selectionEnd;
            this.value = val.slice(0, start) + mappedChar + val.slice(end);

            // Move the caret
            this.selectionStart = this.selectionEnd = start + 1;
        } else if (document.selection && document.selection.createRange) {
            // For IE up to version 8
            var selectionRange = document.selection.createRange();
            var textInputRange = this.createTextRange();
            var precedingRange = this.createTextRange();
            var bookmark = selectionRange.getBookmark();
            textInputRange.moveToBookmark(bookmark);
            precedingRange.setEndPoint("EndToStart", textInputRange);
            start = precedingRange.text.length;
            end = start + selectionRange.text.length;

            this.value = val.slice(0, start) + mappedChar + val.slice(end);
            start++;

            // Move the caret
            textInputRange = this.createTextRange();
            textInputRange.collapse(true);
            textInputRange.move("character", start - (this.value.slice(0,   
start).split("\r\n").length - 1));
            textInputRange.select();
        }

        return false;
    }
};

How do I return the entire list, sequentially? In other words, on the first key event the “T” appears, on the second key event, the “h” appears and so on. I can achieve this in contenteditable divs, but I’m using input type: text fields as I want to autotab between.

The entire code is here: http://jsfiddle.net/NAC77/9/

  • 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-13T18:43:14+00:00Added an answer on June 13, 2026 at 6:43 pm

    Calling $(el).text() on input elements returns an empty string, you should be calling $(el).val(): http://jsfiddle.net/NAC77/10/

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

Sidebar

Related Questions

I have a list defined as <ul id=one> <li>Long sentence of text</li> <li></li> </ul>
I have a sentence that is passed in as a string and I am
I have a sentence that I want to write a shell command to grep
I have a sentence that may have not, or inside. Currently, I'm trying to
I have a string that could have any sentence in it but somewhere in
I have the following sentence #bb John can #20 jiang stone [voila] I want
I have a String variable (basically an English sentence with an unspecified number of
I have a varargs constructor like this : public class Sentence { public String[]
I have a sentence say This is my new program I want to convert
hi i have a sentence (TextView) and I want to tap a certain word

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.