-3

I don't understand the code below. Can someone please give me an explanation?

function deviceNameChange() {           
   if (xmlHttp.readyState==4 || xmlHttp.readyState=="complete")
    {
        var val=xmlHttp.responseText;

        var val1=val.split(',');

        for(var i=0;i<val1.length;i++)
        {
            if(document.getElementById("deviceName").value!=val1[i])
            {
              var anOption = document.createElement("OPTION");      
              document.getElementById("deviceName").options.add(anOption);
              anOption.value=val1[i];
              anOption.innerHTML=val1[i];
            }

        }
    }   
}
Craig S. Anderson
  • 6,966
  • 4
  • 33
  • 46
satish
  • 45
  • 5

1 Answers1

0

This is the return from a HTTP Request of for example

test.php

For more information:

HTTP GET request in JavaScript?

var val=xmlHttp.responseText;
             var val1=val.split(',');
         for(var i=0;i<val1.length;i++)
         {
             if(document.getElementById("deviceName").value!=val1[i])
             {

val is the data we got from the request. It must be a string with

,

because it will get splitted by this.

For more information:

https://developer.mozilla.org/de/docs/Web/JavaScript/Reference/Global_Objects/String/split

For every

i (i is the splitted argument)

in this string it will create an element and insert the value we got from request.

Community
  • 1
  • 1