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?










share|improve this question




















  • 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




    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










  • 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

















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?










share|improve this question




















  • 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




    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










  • 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















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?










share|improve this question















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






share|improve this question















share|improve this question













share|improve this question




share|improve this question








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




    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










  • 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




    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




    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










  • 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














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..






share|improve this answer





















    Your Answer






    StackExchange.ifUsing("editor", function () {
    StackExchange.using("externalEditor", function () {
    StackExchange.using("snippets", function () {
    StackExchange.snippets.init();
    });
    });
    }, "code-snippets");

    StackExchange.ready(function() {
    var channelOptions = {
    tags: "".split(" "),
    id: "1"
    };
    initTagRenderer("".split(" "), "".split(" "), channelOptions);

    StackExchange.using("externalEditor", function() {
    // Have to fire editor after snippets, if snippets enabled
    if (StackExchange.settings.snippets.snippetsEnabled) {
    StackExchange.using("snippets", function() {
    createEditor();
    });
    }
    else {
    createEditor();
    }
    });

    function createEditor() {
    StackExchange.prepareEditor({
    heartbeatType: 'answer',
    convertImagesToLinks: true,
    noModals: true,
    showLowRepImageUploadWarning: true,
    reputationToPostImages: 10,
    bindNavPrevention: true,
    postfix: "",
    imageUploader: {
    brandingHtml: "Powered by u003ca class="icon-imgur-white" href="https://imgur.com/"u003eu003c/au003e",
    contentPolicyHtml: "User contributions licensed under u003ca href="https://creativecommons.org/licenses/by-sa/3.0/"u003ecc by-sa 3.0 with attribution requiredu003c/au003e u003ca href="https://stackoverflow.com/legal/content-policy"u003e(content policy)u003c/au003e",
    allowUrls: true
    },
    onDemand: true,
    discardSelector: ".discard-answer"
    ,immediatelyShowMarkdownHelp:true
    });


    }
    });














     

    draft saved


    draft discarded


















    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
































    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..






    share|improve this answer

























      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..






      share|improve this answer























        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..






        share|improve this answer












        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..







        share|improve this answer












        share|improve this answer



        share|improve this answer










        answered 2 days ago









        Rohit Gupta

        397213




        397213






























             

            draft saved


            draft discarded



















































             


            draft saved


            draft discarded














            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




















































































            Popular posts from this blog

            List item for chat from Array inside array React Native

            Thiostrepton

            Caerphilly