IC SunsetThe developerWorks Connections platform will be sunset on December 31, 2019. On January 1, 2020, this forum will no longer be available. More details available on our FAQ.
Topic
  • 1 reply
  • Latest Post - ‏2014-09-20T11:00:26Z by jitupkp
cel102739
cel102739
1 Post

Pinned topic New innerHTML text doesn't stay

‏2013-07-09T23:56:18Z |

I have utilized code from a tutorial to modify an HTML div, and it works as advertised, but only for about a tenth of a second, after which the original text reappears on the screen.

The form is defined by <form name="searchform" onclick="updateFunction()">

<script>
  var xmlhttp;
  function loadXMLDoc(url,cfunc)
  {
  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=cfunc;
  xmlhttp.open("GET",url,true);
  xmlhttp.send();
  }
   
  function updateFunction()
  {
  loadXMLDoc("results.txt",function()
  {
  if (xmlhttp.readyState==4 && xmlhttp.status==200)
  {
  document.getElementById("results").innerHTML=xmlhttp.responseText;
  }
  });
  }
   
 

</script>

<div id="results">We want the results of the query to appear here</div>

 

The results.txt file contains "These are the results of the submitted query."