Custom function for serialization of form inputs (and selects) Just asking to if following code is ok since i needed didn't find equivalent of .serialize() for vanilla JS. So i invented my own function for plain ol' JS.

    function uzim_vred(phpdoc,parent_id){

    var name = "";
    var val = "";
    var str = phpdoc+"?,";
    var len = ($("#"+parent_id+" [name]").length);
    var i = 0;

    $("#"+parent_id+" [name]").each(function(){

        i++;
        name = $(this).attr('name');
        val = $(this).val();

        str += name+"="+val;

        if(i&lt;len){
            str += "&amp;,"
        }

    });

    i = 0;
    var elems = str.split(",");

    str = "";
    while(i&lt;=len){
        str += elems[i];
        i++
    }


        var xhttp = new XMLHttpRequest();

        xhttp.onreadystatechange = function() {

            if((document.getElementById("raport")!=undefined || document.getElementById("raport")!=null) &amp;&amp; this.readyState == 4 &amp;&amp; this.status == 200){
                document.getElementById("raport").innerHTML = this.responseText;
            }

        };

        xhttp.open("GET", str, false);      
        xhttp.send();

}


How to envoke it:

&lt;button type="button" onclick="uzim_vred('yourPHPscript.php',$(this).parent().attr('id'))"&gt;Send&lt;/button&gt;


First argument is a path to and name of php script, second is used for id of form element from whom you want to "serialize" values.
You are not really implementing in plain JavaScript in that you are using jQuery inside the function. This seems to be an odd choice. Are you using jQuery or not?  You should make a decision. If you are using jQuery, then I don’t know why this function would exist at all. 

The function name itself is meaningless and does not at all convey what the function does. 

You are not url encoding your query string. 

You are not handling case where your asynchronous fails to return 200 response. 

You are using loop counters where you don’t really need to.

It makes no sense how you build a query string then split it apart and then reassemble it. 

Code style is problematic:


inconsistent indentation 
lines of code that are too long