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

  • Home
  • SEARCH
  • 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 4077002
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 20, 20262026-05-20T17:29:46+00:00 2026-05-20T17:29:46+00:00

Hi and thanks for reading. I am trying to permit users to paste text

  • 0

Hi and thanks for reading.

I am trying to permit users to paste text into a textarea field and then work with what they pasted.

The application is limited in scope but users will be pasting the contents of a csv file where the first column lines up with div Ids that I have set up.

For some reason, when I alert within this loop it alerts perfectly. The problem is when I try to prepend() the contents instead of alterting them, it just does nothing:

        $('#datainput').submit(function () {
        csvData = $("#csvData").val();
        csvData = csvData.split('\n');
        var iterationNum;
        var contentText;

        return function() {
            for (var i=0, lngth=csvData.length; i < lngth; i+=1) {
                csvData[i] = csvData[i].split(',');
                if (!!$('#' + csvData[i][0]).length){
                    iterationNum = '#' + csvData[i][0]
                    contentText = '<div class=\"percentageLabel\">' + csvData[i][1] + '</div>';
                    $(iterationNum).prepend(contentText); 
                }
            }   

        }();
    });

This on the other hand works (it works when I alert):

    $('#datainput').submit(function () {
        csvData = $("#csvData").val();
        csvData = csvData.split('\n');
        var iterationNum;
        var contentText;

        return function() {
            for (var i=0, lngth=csvData.length; i < lngth; i+=1) {
                csvData[i] = csvData[i].split(',');
                if (!!$('#' + csvData[i][0]).length){
                    iterationNum = '#' + csvData[i][0]
                    contentText = '<div class=\"percentageLabel\">' + csvData[i][1] + '</div>';
                    alert(iterationNum + contentText); 
                }
            }   

        }();
    }); 

I’ve even tested by replacing the iterationNum variable with an actual id like #MyID for example and it does not work within the loop. Using the each same expression outside of the loop the prepend works:

                        contentText = '<div class=\"percentageLabel\"></div>';
                    $(MyID).prepend(contentText); 

But if I use that code within the loop I get nothing.

Can you spot what I’m doing wrong here?

The first code snippet above is the one I want to work, the others are simply to show what else I’ve tried

  • 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-20T17:29:47+00:00Added an answer on May 20, 2026 at 5:29 pm

    It seems like in:

    iterationNum = '#' + csvData[i][0]; /* Don't forget your ;'s! */
    contentText = '<div class=\"percentageLabel\">' + csvData[i][1] + '</div>';
    $(iterationNum).prepend(contentText);
    

    $(iterationNum) may not be a valid selector. Change it to:

    iterationNum = '#' + csvData[i][0]; /* Don't forget your ;'s! */
    contentText = '<div class=\"percentageLabel\">' + csvData[i][1] + '</div>';
    alert(( $(iterationNum)[0] != null  ));
    

    And tell me whether it alerts true or false.

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

Sidebar

Related Questions

Thanks for reading. I'm a bit new to jQuery, and am trying to make
Thanks for reading. I'm trying to put a label and an image on a
and thanks for reading. I am building a data entry form. I am trying
Thanks for reading this. I am dynamically generating some data which includes a select
Thanks for reading this. I have markup similar to what is below. Using the
Thanks for reading this I thought I could use find(), but couldn't make it
Thanks for reading this. I would have thought it would be as simple as
I'm reading about Rails fixtures in this guide (thanks, trevorturk). It appears you define
Thanks for reading this. I imagine this is really a javascript question, and my
Hello everyone and thanks for reading... I'm a Mono / Web developer and was

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.