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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 17, 20262026-06-17T14:27:18+00:00 2026-06-17T14:27:18+00:00

I have a text box that will have a large block of text pasted

  • 0

I have a text box that will have a large block of text pasted into it.

Then I parse the text into an array, removing whitespace. I need to pull the data out of certain array elements and put them into separate variables so I can generate a cleaner, formatted output.

The problem is that noting appears to be passed into my variables from the array. I’ve toyed with it a bit, and the array is being filled correctly, but the elements aren’t passing strings to the variable.

HTML:

<p>Contact Name: <b id='contactNameOutput'></b></p>

JavaScript:

function generateOutputfvoc() {
    var inputArr = document.getElementById('inputBox').value.split(/[\s]/);
    document.getElementById('contactNameOutput').innerHTML = inputArr[0];
}
  • 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-17T14:27:20+00:00Added an answer on June 17, 2026 at 2:27 pm

    There are quite a few things going on here wich are hard to understand why you’ve done them.
    My asumption is that inputBox is either a textarea or a input field into wich the user writes something.

    Okay so you’re splitting that string on whitespaces so for example the string

    The quick brown fox

    would result in a array which looks like this:

    inputArr = ["The", "quick", "brown", "fox"]
    

    Now in your for-loop you’re iterating over this array, starting at 0 and incrementing till you reach the end of the array, nothing strange here.

    But in the first iteration, in the if-clause that you have, you’re trying to access the array with negative values, remember i is 0, this results in an undefined value, also in the last part of the if clause you’re trying to access i+1 well what happens when i is at its last value?! You guessed it another undefined! Later the loop will access old values which you’ve allready gone through, and honestly I can’t figure out what you’re trying to accomplish.

    All your if-statements are a mess really, especially if your gonna do them in that loop.
    My guess is that you thought that you needed a for-loop for this, when in fact you do not.

    What you have is one array containing the words in your textarea, if you know the order of what you’re expecting, (can you really know what the user will put in that textarea?), then you can just access the words directly since you’ll know the index of each item in the array. Otherwise, rewrite this to something simpler, always try to keep it simple.

    Also why not look up refactoring while you’re at it?!

    edit

    I think that the problem you have now is that the first element in the array is an empty string, that happens if there’s a space in the beginning of the input.

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

Sidebar

Related Questions

I have a text box that will allow the user to enter multiple authors
I want to have a small text box with a scroll bar that will
I have a text box that accepts integers, and I need it to run
I have text box and what happens is that the user will click on
I have a text box that will have a currency string in it that
I have a text box that contains lines of data similar to this: sheep
I have a text box that is going to be populated with a comma
I have a rich text box that is being updated with log information. There
I have one text box on that text box i am using required field
I have an Asp.net text box that is being auto populated by javascript using

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.