Hello! There is such a code: https://jsfiddle.net/alcheez/h5vjodx3/

$(document).ready(function(){ $("button").click(function(){ var x = $("form").serializeArray(); $.each(x, function(i, field){ $("#results").append(this.value); }); }); }); 
 <script src="https://ajax.googleapis.com/ajax/libs/jquery/3.1.1/jquery.min.js"></script> <form action=""> First name: <input type="text" name="FirstName" value="Mickey"><br> Last name: <input type="text" name="LastName" value="Mouse"><br> </form> <button>Serialize form values</button> <div id="results"></div> 

I managed to get the value of the form and now I need to, say, insert these values ​​into a simple paragraph, for example:

 <p>ЗдравствуйтС, ΠΌΠΎΡ‘ имя (Mickey), Π° моя фамилия (Mouse).</p> 

I do not understand how this can be achieved, how to write the values ​​of form fields in the places I need, help, please.

    1 answer 1

    If you just need to form a paragraph, you can do it like this:

     $("button").click(function(){ $("#results").append('<p>ЗдравствуйтС, ΠΌΠΎΡ‘ имя ' + $('form input[name="FirstName"]').val() + ', Π° моя фамилия ' + $('form input[name="LastName"]').val() + '.</p>'); }); 

    either so:

     $("button").click(function(){ var x = $("form").serializeArray(); var values = {}; $.each(x, function(i, field){ values[this.name] = this.value; }); $("#results").append('<p>ЗдравствуйтС, ΠΌΠΎΡ‘ имя ' + values.FirstName + ', Π° моя фамилия ' + values.LastName + '.</p>'); }); 
    • Thank you very much, you really helped - Alexander Syrokvasovsky
    • and if I need, for example, to generate some sort of file, and insert these values ​​there? I mean, is it possible to somehow use this data outside the function? - Alexander Syrokvasovsky