title: Javascript document.getElementById concatenating
body: <p>I'm struggling with some JavaScript code that I have used countless times across my pages just tweaking as I go. The problem I have is concatenating part of the form elements id and a string variable defined elsewhere in the page to make my ajax call dynamic.
  Im am using the following code which works perfect when the element is hard coded as below(only works for the item coded and not dynamically so no good after testing)</p>
  
  <pre><code>&lt;script type="text/javascript"&gt;
  function edttodo(str)
  {
  if (str=="")
  {
  document.getElementById("todoitemwr").innerHTML="";
  return;
  } 
  if (window.XMLHttpRequest)
  {// code for IE7+, Firefox, Chrome, Opera, Safari
  xmlhttp=new XMLHttpRequest();
  }
  else
  {// code for IE6, IE5
  xmlhttp=new ActiveXObject("Microsoft.XMLHTTP");
  }
  xmlhttp.onreadystatechange=function()
  {
  if (xmlhttp.readyState==4 &amp;&amp; xmlhttp.status==200)
  {
  document.getElementById("todoitemwr(2)").innerHTML=xmlhttp.responseText;
  }
  }
  xmlhttp.open("GET","todo/edt_todo.php?q="+str,true);
  xmlhttp.send();
  }
  &lt;/script&gt;
  </code></pre>
  
  <p>So you understand what my need is for the dynamic aspect of the code I have a mysql query undertaken which is as follows:</p>
  
  <pre><code>&lt;?php 
              //Get Current To-Do Items
  
              //select database
              mysql_select_db("jbsrint", $con);
              //query users_dash_user
              $result1 = mysql_query("SELECT * FROM todo WHERE todo_user_id_fk= '".$_SESSION['user_id']."' AND todo_item_status='1'");
  
              while($row1 = mysql_fetch_array($result1))
              {                               
              echo"&lt;div class=\"todoitemwr\" name=\"todoitemwr(". $row1['todo_id'] .")\" ID=\"todoitemwr(". $row1['todo_id'] .")\"&gt;&lt;span class=\"todoitem\"&gt;" . $row1['todo_item'] . "&lt;/span&gt;&lt;span class=\"rmv\" onclick=\"rmvtodo(". $row1['todo_id'] .")\" onmouseover=\"className='rmvon';\" onmouseout=\"className='rmv';\"&gt;X&lt;/span&gt;&lt;img src=\"images/edit.png\" class=\"edt\" onclick=\"edttodo(". $row1['todo_id'] .")\"&gt;&lt;/img&gt;&lt;/div&gt;";
              }
              ?&gt;
              &lt;/div&gt;
  </code></pre>
  
  <p>As you can see the div id is dynamically named based on the id of the information that has been retrieved. The use of my ajax code above is to be able to edit the text that is retrieved in-situ and once corrected/altered it can then be re-submitted and update that record.</p>
  
  <p>I'm sure that it is simply a case of understanding how JavaScript requires me to combine the text and str value in the document.getElementById("todoitemwr(2)") part.</p>
  
  <p>As usual any help is much appreciated.</p>
  
  <p>Alan.</p>