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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 5, 20262026-06-05T18:07:28+00:00 2026-06-05T18:07:28+00:00

I have a form consisting of a textarea, with line numbers thanks to Javascript.

  • 0

I have a form consisting of a textarea, with line numbers thanks to Javascript.
I use this form to validate JSON, just like jsonlint.org does it.
The user enters some JSON, presses validate, and gets back the answer.
I am not parsing the file myself, I use a python command :

python -m json.tool input.json

As you can see, this command takes a file. So what I am doing is the following :

  • write form data to the file
  • run this command and get output
  • if no error, output to screen “Valid JSON” like jsonlint.org
    else show error message given by the program : “Error …. line x column y (char z)”

The line number given by the Python program corresponds to the one in the file and not to the one from textarea … making my Javascript linenumbers useless. Finding a correspondence btw the 2 is giving me a hard time because it depends on the width of my textarea, and the font I’m using in it, and understanding how line numbers in files are set (which I do not really understand)

How could I find a correspondence btw the 2 ?

Thanks

JUST REALISING : my textarea looks exactly the same as the one you type in when you ask a question on SOF 😀

—– EDIT as response to Ben —–
Very interesting. I implemented the feature I asked for using an option of the textarea called “wrap”. I set to “soft” :

<form method='post' action='/exec' id="jsonform" >
       <textarea wrap="hard" name="json" id="json_input" rows="20" cols="150" placeholder="Enter JSON to validate.">{{ resp | safe }}</textarea>
       <div align="center">
       <input type='submit' value='Validate' id="button" >
       </div>
    </form>

However, this makes valid JSON invalid. Because the Python module expects to have quotes before the break-line …
So I need to feed the validator with data from the form with textarea=”soft”, and show the data from the form with textarea=”hard” . But I have one form.
Also I tried the code given on the post you gave me, but it didn’t work for some reason. And I don’t know Javascript (need to change that.) so I couldn’t debug or adapt the code …
HELLLP

  • 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-05T18:07:29+00:00Added an answer on June 5, 2026 at 6:07 pm

    Instead of trying to derive your lines after the fact, you’re probably better off putting in markers before you send the data to be tested. finding "line-breaks" in textarea that is word-wrapping ARABIC text looks like it has a pretty robust technique for forcing line breaks at all line wraps. If the line breaks used by the textarea and the lien breaks used by the file are not the same, you should still find it relatively easy to convert from one to the other in transit. If you don’t want to perturb it because you want the user to be able to edit it without the additional line breaks if/when it comes back invalid, then I’d suggest cloning the textarea to a space inside a “display:none” div or equivalent setup. Mangle and test the clone as appropriate, and then put the feedback on the untouched visible original. If the file has an autowrap width, then you’ll have to make sure that the autowrap width of the textarea is shorter, but that shoudln’t be difficult, and I’d be a bit surprised if it was an issue to begin with.

    Edit: if the python module has to have quotes before the break-line, you’re in a bit of trouble anyway – anyone can put in hard break-lines manually at any time just by hitting enter. My suggestion there would be to have some sort of processor function in between the Json and the file that went and put appropriate quotes just before line breaks – although I may be misunderstanding things a bit here.

    If you want multiple copies of your form to play with, though, that’s totally doable. You do need to use jQuery, but jQuery is worth learning anyway. (It’s somewhat frustrating until you figure it out, and then after you figure it out it’s the best thing that ever happened to javascript and you’ll never want to be without it.) Include the most recent copy of jQuery (it’s a javascript plugin). The clone() function will let you create an exact duplicate of your existing textarea (or form, or any other DOM object, really) at time of cloning (ie, it’ll have all the text written into it). The insertBefore() and/or insertAfter() functions will let you put it anywhere in the page you want – perhaps inside a <div style="display:none"></div> so that you can muck around with it as much as you like without doing anything visible on the screen.

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

Sidebar

Related Questions

I have an html form consisting of just radio buttons. The 2nd line of
I have a very simple form, consisting of a textarea and a submit button.
I have a Java applet consisting of a wizard-like form with three steps. At
I have a usual login form consisting of two input fields, one for login,
I have a form with multiple dropdowns consisting of multiple values. I'm trying to
I have two window form applications written in C, one holds a struct consisting
I have form where user submits field. Field can have letters, numbers, and punctuation.
I have form, where some fields are looks like rows, so I can add/delete
I have form in my page, I am using ajax.beginform(). Inside this form I
i have form with user data to input and javascript ajax to send information

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.