


Using JavaScript how to extract textbox content through loop and convert it to JSON format to display in new window
How to extract the text box content in a loop in javascript and make it into json format and send it to a new window for display
Your ids are not consecutive, this id attribute is useless
I think of two methods
1,
You can take out all the text boxes on the page and traverse the dom or use jquery $("texterea") or querySelectorAll("textarea")
var data={},nodes=querySelectorAll("textarea");//All text boxes may be useful
for(var i=0,l=nodes.length;i data[nodes[i].id]=nodes[i].value; //If there are text boxes that do not meet the conditions, you can also filter them out }; var json=JSON.stringify(data);//Json comes out and is sent to a new page? I don’t know what you want 2. When your program outputs the page, it should also output json. The prerequisite is that the page is written by you
How to get data from json
Expand All
According to the returned string, it can be seen that it is in the form of a js array spliced into multiple jsons.
If only a string is returned, the string must be converted into a js object.
Use Jquery's $.each() method to loop through the js array to retrieve the data of each json object.
str = '[{"key":"value","keys":[{"key1":"value1","key2":"value2"},{"key1":"value3","key2 ":"value4"}],"obj":{"id":1,"msg":"success"}}]';
str_json = eval("(" str ")"); //Convert string into js object
$.each(str_json,fucntion(a,b){
alert(a); //Pop up the key of the array
alert(b.id);//Pop up the data to be taken out
});
How does JS javascript convert an ordinary array into a JSON array
First of all, there is a syntax error in your array~
In JS, json is a string representation. Your B is obviously an object and has nothing to do with json~
So it is converting between js objects (arrays) and json strings~
Then your A (the example in js uses Camel rules, so it should be written as a lowercase a) should be written as:
var a = {
name: "XXXX", //Attributes are also Camel rules
year: 1990,
old: 21
};
Then there is the conversion problem, using the JSON class:
var b = JSON.stringify(a); //Note that b is a json string
If the JSON object cannot be found, your browser version is too old
You need to manually reference the json class library
Please download and quote "json2.js" by yourself
Hope it helps you~
By Billskate
How does JS write json format data into an array
json array zhidao is also an array
//1,
var jsonstr="[{'name':'a','value':1},{'name':'b','value':2}]";
var jsonarray = eval('(' jsonstr ')');
var arr =
{
"name" : $('#names').val(),
"value" : $('#values').val()
}
jsonarray.push(arr);
//2,
var json={};//Define a json object
json.array1=["2","4"];//Add a new attribute, this attribute is an array
json.array1[json.array1.length]='6'; //Append an element to the array
alert(json.array1)
The above is the detailed content of Using JavaScript how to extract textbox content through loop and convert it to JSON format to display in new window. For more information, please follow other related articles on the PHP Chinese website!

Hot AI Tools

Undresser.AI Undress
AI-powered app for creating realistic nude photos

AI Clothes Remover
Online AI tool for removing clothes from photos.

Undress AI Tool
Undress images for free

Clothoff.io
AI clothes remover

Video Face Swap
Swap faces in any video effortlessly with our completely free AI face swap tool!

Hot Article

Hot Tools

Notepad++7.3.1
Easy-to-use and free code editor

SublimeText3 Chinese version
Chinese version, very easy to use

Zend Studio 13.0.1
Powerful PHP integrated development environment

Dreamweaver CS6
Visual web development tools

SublimeText3 Mac version
God-level code editing software (SublimeText3)

Hot Topics











Have you ever encountered a black screen after installing a graphics driver like an Nvidia driver in Windows 10/11? Now in this post from php.cn, you can find a couple of worth trying solutions to the Nvidia driver update black screen.

KB2267602 is a protection or definition update for Windows Defender designed to fix vulnerabilities and threats in Windows. Some users reported that they were unable to install KB2267602. This post from php.cn introduces how to fix the “KB2267602 fai

Data recovery is always a heated topic. To successfully restore data from your device, you should know how it stores data. You can learn the difference between RAID recovery and hard drive recovery from this php.cn post.

File system errors commonly happen on people’s computer and the error can trigger a series of linked malfunctions. This article on php.cn Website will give you a series of fixes to targeting the file system error (-1073741521). Please keep on with yo

The Security tab in File Properties helps set different permissions for different groups and users to a file or folder. Some users find that Windows 11 Security tab missing from File Properties. This post from php.cn gives some methods to fix it.

Seeing a black folder background Windows 10/11 when you open File Explorer? In this post from php.cn Solution, you will learn a couple of useful solutions to remove the black background in folders.

Are you struggling with the “the file can’t be displayed” error when accessing the specific folder? Some users are complaining about this trouble and looking for useful measures. This article about the file can’t be displayed OneDrive from php.cn wil

Some users report that they meet the Windows Server auto-shutdown issue after the license expires. This post from php.cn teaches you how to stop expired Windows Server auto-shutdown. Now, keep on your reading.
