JavaScript - change value of two elements from a list
up vote
-2
down vote
favorite
I want to change the values of two elements from a list, it's hard to explain so I'll put it like this.
I have a list that looks like this
Adam Tyson
Emil Johnsson
Fredrick Connor
Lars Hamilton
I want to put it in a for loop, like this.
for(var i = 0; i < 1000; i++) {
document.getelementbyid('firstname').innerHTML = param[0];
document.getelementbyid('lastname').innerHTML = param[1];
submit();
}
But I have no idea how I can make the firstname equal e.g param[0]. And also, once it has submitted that it will jump to line 2, and then 3, etcetera and keep doing the same thing. What I basically want to do is submit a form with all these names using a loop.
Any ideas?
javascript jquery arrays list
add a comment |
up vote
-2
down vote
favorite
I want to change the values of two elements from a list, it's hard to explain so I'll put it like this.
I have a list that looks like this
Adam Tyson
Emil Johnsson
Fredrick Connor
Lars Hamilton
I want to put it in a for loop, like this.
for(var i = 0; i < 1000; i++) {
document.getelementbyid('firstname').innerHTML = param[0];
document.getelementbyid('lastname').innerHTML = param[1];
submit();
}
But I have no idea how I can make the firstname equal e.g param[0]. And also, once it has submitted that it will jump to line 2, and then 3, etcetera and keep doing the same thing. What I basically want to do is submit a form with all these names using a loop.
Any ideas?
javascript jquery arrays list
1
Read about AJAX, or seems like this is what you want to do. Perhaps you want to use something like jQuery.post().
– Frax
2 days ago
2
getelementbyidmust begetElementById. Also, thefor-loop makes zero sense as of now because you're not usingiinside, which means you keep repeating exactly the same code.
– connexo
2 days ago
OP, wrt AJAX: you don't necessarily need to add the data to the HTML form first and then submit the form. If the server allows it you can just submit a stringified version of the array/object instead.JSON.stringify(arr).
– Andy
2 days ago
Please post and update stackoverflow.com/help/mcve Put your HTML, your source of "list", any (other) code you have tried. Please also include the exact results you expect.
– Mark Schultheiss
2 days ago
I agree with others that what you describe is typically done via Ajax via a POST - scroll down here for an example: api.jquery.com/jquery.ajax or here for a shorthand version api.jquery.com/jquery.post
– Mark Schultheiss
2 days ago
add a comment |
up vote
-2
down vote
favorite
up vote
-2
down vote
favorite
I want to change the values of two elements from a list, it's hard to explain so I'll put it like this.
I have a list that looks like this
Adam Tyson
Emil Johnsson
Fredrick Connor
Lars Hamilton
I want to put it in a for loop, like this.
for(var i = 0; i < 1000; i++) {
document.getelementbyid('firstname').innerHTML = param[0];
document.getelementbyid('lastname').innerHTML = param[1];
submit();
}
But I have no idea how I can make the firstname equal e.g param[0]. And also, once it has submitted that it will jump to line 2, and then 3, etcetera and keep doing the same thing. What I basically want to do is submit a form with all these names using a loop.
Any ideas?
javascript jquery arrays list
I want to change the values of two elements from a list, it's hard to explain so I'll put it like this.
I have a list that looks like this
Adam Tyson
Emil Johnsson
Fredrick Connor
Lars Hamilton
I want to put it in a for loop, like this.
for(var i = 0; i < 1000; i++) {
document.getelementbyid('firstname').innerHTML = param[0];
document.getelementbyid('lastname').innerHTML = param[1];
submit();
}
But I have no idea how I can make the firstname equal e.g param[0]. And also, once it has submitted that it will jump to line 2, and then 3, etcetera and keep doing the same thing. What I basically want to do is submit a form with all these names using a loop.
Any ideas?
javascript jquery arrays list
javascript jquery arrays list
edited 2 days ago
Shiladitya
9,29391830
9,29391830
asked 2 days ago
PVP Squad
13
13
1
Read about AJAX, or seems like this is what you want to do. Perhaps you want to use something like jQuery.post().
– Frax
2 days ago
2
getelementbyidmust begetElementById. Also, thefor-loop makes zero sense as of now because you're not usingiinside, which means you keep repeating exactly the same code.
– connexo
2 days ago
OP, wrt AJAX: you don't necessarily need to add the data to the HTML form first and then submit the form. If the server allows it you can just submit a stringified version of the array/object instead.JSON.stringify(arr).
– Andy
2 days ago
Please post and update stackoverflow.com/help/mcve Put your HTML, your source of "list", any (other) code you have tried. Please also include the exact results you expect.
– Mark Schultheiss
2 days ago
I agree with others that what you describe is typically done via Ajax via a POST - scroll down here for an example: api.jquery.com/jquery.ajax or here for a shorthand version api.jquery.com/jquery.post
– Mark Schultheiss
2 days ago
add a comment |
1
Read about AJAX, or seems like this is what you want to do. Perhaps you want to use something like jQuery.post().
– Frax
2 days ago
2
getelementbyidmust begetElementById. Also, thefor-loop makes zero sense as of now because you're not usingiinside, which means you keep repeating exactly the same code.
– connexo
2 days ago
OP, wrt AJAX: you don't necessarily need to add the data to the HTML form first and then submit the form. If the server allows it you can just submit a stringified version of the array/object instead.JSON.stringify(arr).
– Andy
2 days ago
Please post and update stackoverflow.com/help/mcve Put your HTML, your source of "list", any (other) code you have tried. Please also include the exact results you expect.
– Mark Schultheiss
2 days ago
I agree with others that what you describe is typically done via Ajax via a POST - scroll down here for an example: api.jquery.com/jquery.ajax or here for a shorthand version api.jquery.com/jquery.post
– Mark Schultheiss
2 days ago
1
1
Read about AJAX, or seems like this is what you want to do. Perhaps you want to use something like jQuery.post().
– Frax
2 days ago
Read about AJAX, or seems like this is what you want to do. Perhaps you want to use something like jQuery.post().
– Frax
2 days ago
2
2
getelementbyid must be getElementById. Also, the for-loop makes zero sense as of now because you're not using iinside, which means you keep repeating exactly the same code.– connexo
2 days ago
getelementbyid must be getElementById. Also, the for-loop makes zero sense as of now because you're not using iinside, which means you keep repeating exactly the same code.– connexo
2 days ago
OP, wrt AJAX: you don't necessarily need to add the data to the HTML form first and then submit the form. If the server allows it you can just submit a stringified version of the array/object instead.
JSON.stringify(arr).– Andy
2 days ago
OP, wrt AJAX: you don't necessarily need to add the data to the HTML form first and then submit the form. If the server allows it you can just submit a stringified version of the array/object instead.
JSON.stringify(arr).– Andy
2 days ago
Please post and update stackoverflow.com/help/mcve Put your HTML, your source of "list", any (other) code you have tried. Please also include the exact results you expect.
– Mark Schultheiss
2 days ago
Please post and update stackoverflow.com/help/mcve Put your HTML, your source of "list", any (other) code you have tried. Please also include the exact results you expect.
– Mark Schultheiss
2 days ago
I agree with others that what you describe is typically done via Ajax via a POST - scroll down here for an example: api.jquery.com/jquery.ajax or here for a shorthand version api.jquery.com/jquery.post
– Mark Schultheiss
2 days ago
I agree with others that what you describe is typically done via Ajax via a POST - scroll down here for an example: api.jquery.com/jquery.ajax or here for a shorthand version api.jquery.com/jquery.post
– Mark Schultheiss
2 days ago
add a comment |
1 Answer
1
active
oldest
votes
up vote
0
down vote
What is understand actually you have list of names and you want to show all to store the names of the list then you need to post them. I think you will first have to create the first name last name for each rows
like given below
var parent = document.getElementById("parentDiv"); // this is my assumption please change as per your need
for(var i = 0; i < 1000; i++) {
var firstNameFinal = firstName +i;
var firstNameInput = document.createElement("input");
firstNameInput.setAttribute('type', 'text');
firstNameInput.setAttribute('id', 'firstNameFinal');
parent.appendChild(firstNameInput);
var lastnameFinal = lastname + i;
var lastNameInput = document.createElement("input");
lastNameInput.setAttribute('type', 'text');
lastNameInput.setAttribute('id', 'lastnameFinal');
parent.appendChild(lastNameInput);
document.getelementbyid('firstNameFinal').innerHTML = param[0];
document.getelementbyid('lastnameFinal').innerHTML = param[1];
}
submit();
Please reply..
add a comment |
1 Answer
1
active
oldest
votes
1 Answer
1
active
oldest
votes
active
oldest
votes
active
oldest
votes
up vote
0
down vote
What is understand actually you have list of names and you want to show all to store the names of the list then you need to post them. I think you will first have to create the first name last name for each rows
like given below
var parent = document.getElementById("parentDiv"); // this is my assumption please change as per your need
for(var i = 0; i < 1000; i++) {
var firstNameFinal = firstName +i;
var firstNameInput = document.createElement("input");
firstNameInput.setAttribute('type', 'text');
firstNameInput.setAttribute('id', 'firstNameFinal');
parent.appendChild(firstNameInput);
var lastnameFinal = lastname + i;
var lastNameInput = document.createElement("input");
lastNameInput.setAttribute('type', 'text');
lastNameInput.setAttribute('id', 'lastnameFinal');
parent.appendChild(lastNameInput);
document.getelementbyid('firstNameFinal').innerHTML = param[0];
document.getelementbyid('lastnameFinal').innerHTML = param[1];
}
submit();
Please reply..
add a comment |
up vote
0
down vote
What is understand actually you have list of names and you want to show all to store the names of the list then you need to post them. I think you will first have to create the first name last name for each rows
like given below
var parent = document.getElementById("parentDiv"); // this is my assumption please change as per your need
for(var i = 0; i < 1000; i++) {
var firstNameFinal = firstName +i;
var firstNameInput = document.createElement("input");
firstNameInput.setAttribute('type', 'text');
firstNameInput.setAttribute('id', 'firstNameFinal');
parent.appendChild(firstNameInput);
var lastnameFinal = lastname + i;
var lastNameInput = document.createElement("input");
lastNameInput.setAttribute('type', 'text');
lastNameInput.setAttribute('id', 'lastnameFinal');
parent.appendChild(lastNameInput);
document.getelementbyid('firstNameFinal').innerHTML = param[0];
document.getelementbyid('lastnameFinal').innerHTML = param[1];
}
submit();
Please reply..
add a comment |
up vote
0
down vote
up vote
0
down vote
What is understand actually you have list of names and you want to show all to store the names of the list then you need to post them. I think you will first have to create the first name last name for each rows
like given below
var parent = document.getElementById("parentDiv"); // this is my assumption please change as per your need
for(var i = 0; i < 1000; i++) {
var firstNameFinal = firstName +i;
var firstNameInput = document.createElement("input");
firstNameInput.setAttribute('type', 'text');
firstNameInput.setAttribute('id', 'firstNameFinal');
parent.appendChild(firstNameInput);
var lastnameFinal = lastname + i;
var lastNameInput = document.createElement("input");
lastNameInput.setAttribute('type', 'text');
lastNameInput.setAttribute('id', 'lastnameFinal');
parent.appendChild(lastNameInput);
document.getelementbyid('firstNameFinal').innerHTML = param[0];
document.getelementbyid('lastnameFinal').innerHTML = param[1];
}
submit();
Please reply..
What is understand actually you have list of names and you want to show all to store the names of the list then you need to post them. I think you will first have to create the first name last name for each rows
like given below
var parent = document.getElementById("parentDiv"); // this is my assumption please change as per your need
for(var i = 0; i < 1000; i++) {
var firstNameFinal = firstName +i;
var firstNameInput = document.createElement("input");
firstNameInput.setAttribute('type', 'text');
firstNameInput.setAttribute('id', 'firstNameFinal');
parent.appendChild(firstNameInput);
var lastnameFinal = lastname + i;
var lastNameInput = document.createElement("input");
lastNameInput.setAttribute('type', 'text');
lastNameInput.setAttribute('id', 'lastnameFinal');
parent.appendChild(lastNameInput);
document.getelementbyid('firstNameFinal').innerHTML = param[0];
document.getelementbyid('lastnameFinal').innerHTML = param[1];
}
submit();
Please reply..
answered 2 days ago
Rohit Gupta
397213
397213
add a comment |
add a comment |
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
StackExchange.ready(
function () {
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f53239129%2fjavascript-change-value-of-two-elements-from-a-list%23new-answer', 'question_page');
}
);
Post as a guest
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
1
Read about AJAX, or seems like this is what you want to do. Perhaps you want to use something like jQuery.post().
– Frax
2 days ago
2
getelementbyidmust begetElementById. Also, thefor-loop makes zero sense as of now because you're not usingiinside, which means you keep repeating exactly the same code.– connexo
2 days ago
OP, wrt AJAX: you don't necessarily need to add the data to the HTML form first and then submit the form. If the server allows it you can just submit a stringified version of the array/object instead.
JSON.stringify(arr).– Andy
2 days ago
Please post and update stackoverflow.com/help/mcve Put your HTML, your source of "list", any (other) code you have tried. Please also include the exact results you expect.
– Mark Schultheiss
2 days ago
I agree with others that what you describe is typically done via Ajax via a POST - scroll down here for an example: api.jquery.com/jquery.ajax or here for a shorthand version api.jquery.com/jquery.post
– Mark Schultheiss
2 days ago