title: How to get <span id= var
body: <p>I’m working at a web GUI for an audio mixer. Therefor I have lot of repetitive faders. All looking the same, just differing by ID. The ID is a three digit number. The first digit is provide by the main php page, the other are repetitive in each fader section. I’m trying to get the result back from the server and posting it into a span field. The problem is that the span id depends on the full id.</p>
  
  <p>The span id should be “result111”.Not hardcoded as it is but dynamically generated by the provide id followed by the identifier 11.</p>
  
  <p><div class="snippet" data-lang="js" data-hide="false" data-console="true" data-babel="false">
  <div class="snippet-code">
  <pre class="snippet-code-js lang-js prettyprint-override"><code>GUI php
  &lt;script&gt;
  function transfer(value,id)
  {
   if (window.XMLHttpRequest)
   {
     // AJAX nutzen mit IE7+, Chrome, Firefox, Safari, Opera
     xmlhttp=new XMLHttpRequest();
    }
    else
    {
      // AJAX mit IE6, IE5
      xmlhttp=new ActiveXObject("Microsoft.XMLHTTP");
    }
    xmlhttp.onreadystatechange=function()
   {
     if (xmlhttp.readyState==4 &amp;&amp; xmlhttp.status==200)
     {
      document.getElementById("result"+id).innerHTML=xmlhttp.responseText;
     }
   }
    xmlhttp.open("GET","backEnd.php?v="+value+"&amp;id="+id,true);
    xmlhttp.send();
   return;
  }
  &lt;/script&gt;</code></pre>
  <pre class="snippet-code-css lang-css prettyprint-override"><code>backEnd.php
  
  &lt;?php
  $id = 10;
  $value = 7;
  $result = 6;
  if ( isset($_GET['id']) )
  {
     $id = $_GET['id'];
  }
  if ( isset($_GET['v']) )
  {
     $value = $_GET['v'];
     $result = $value;
  }
  echo ("$id + $result");
  ?&gt;
  
  GUI.php
  &lt;?php
   $id = 1;
   include 'fader.php';
  ?&gt;</code></pre>
  <pre class="snippet-code-html lang-html prettyprint-override"><code> fader.php
    
    
  &lt;script&gt;
   var id = &lt;?php echo "$id"; ?&gt;;
   function setName (id2){
    var fullId =""+ id + id2;
    return fullId;
   }
   function setNameReturn (id2){
    var fullIdReturn =""+ id + id2;
    return fullIdReturn;
   }
   &lt;/script&gt;
    
    &lt;form oninput="transfer(auswertung.value,setName(11))"&gt;
      &lt;input type="range" name="auswertung" min="0" max= "63" value="30" orient="vertical"&gt;
      &lt;br&gt;
      &lt;span id="setNameReturn (11)"&gt;n.a.&lt;/Span&gt;
   &lt;/form&gt;</code></pre>
  </div>
  </div>
  </p>