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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 6, 20262026-06-06T04:30:13+00:00 2026-06-06T04:30:13+00:00

I would like two next boxes on a page, You can then copy/paste text

  • 0

I would like two next boxes on a page, You can then copy/paste text into them and using JavaScript compare the two.

<textarea id="first"></textarea>
<textarea id="second"></textarea>

Using JavaScript I would then like to compare the two, line by line with something simple such as

if [line X of id="first"] != [line X of id="second"]

Then I would like to highlight said lines.

I’m not sure how to access the value of a textarea line by line or would i need to get the whole value and split it into an array?

Would someone please provide me with the syntax to access the text area line by line?

Also if you think I’m going about this wrong or their is a easier way please let me know!

EDIT:
Here is my complete solution:

HTML

<!DOCTYPE html>
<html>
<head><script src="split.js?" type="text/javascript"></script>
</head>
<body>
<textarea style="float: left; width: 45%" id="first" name="comments" autocomplete="off" cols="40" rows="5" width="50%"></textarea>
<textarea style="float: right; width: 45%" id="second" name="second" autocomplete="off" cols="40" rows="5"></textarea><br>
<button onClick="compare()">Compare</button>
<br><br><br><br><br><br><br><center><div id="results"></div></center>
</body>
</html>

Javascript

function compare() {
    document.getElementById('results').innerHTML = "";
    var first = document.getElementById("first");
    var second = document.getElementById("second");
    if(document.all) { // IE
        var f = first.value.split("\r\n");
        var s = second.value.split("\r\n");
    } else { //Mozilla
        var f = first.value.split("\n");
        var s = second.value.split("\n");
    }
    for(var i=0; i<f.length; i++) {
        if (f[i] !== s[i]) {
            var row = i;
            row++
            document.getElementById('results').appendChild(document.createTextNode("Box 1 Does not Match Box 2 on line: " + row));
            document.getElementById('results').appendChild(document.createElement('br'));
        }
    }
};

Bit noobish but I’m learning!

  • 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-06T04:30:15+00:00Added an answer on June 6, 2026 at 4:30 am
    text1 = document.getElementById("first").value.split("\n");
    text2 = document.getElementById("second").value.split("\n");
    
    var limit =  text1.length > text2.length ?  text1.length : text2.length;
    
    for(i=0;i<limit ; i++)
    {
        if(text1[i] == text2[i])
        {
            alert(true);
        }
        else
        {
            alert(false);
        }
    }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I would like a two-column web page with the right panel fixed-width and the
I would like to loop through two lists using a For each loop. dim
I have created two rounded corner boxes which i would like to be aligned
I'm using aps article based LaTeX template and I would like to put two
I have two elements (a field and some text) that I would like to
I am using jQuery Ui Autocomplete 1.8.14 and I would like to do two
There are two scenarios for an ASP.net webforms page which I would like to
I would like my two applications to be able to send strings to each
I have a problem i would like parallelize two for loops with openmp. how
I would like to build two C++ projects in the same solution in Visual

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.