|
Subject:
|
var as variable
|
|
Posted By:
|
incredi-man
|
Post Date:
|
9/16/2006 3:39:51 AM
|
How can i pass info to a variable id tag with innerHTML?
This is what i tried.Say results[0] gives back 2, i want to update de info in <TD id='tag2'>. This gives no error, but no result aswell.
var vtag = 'tag'+trim(results[0]); vtag.innerHTML= results[1]; .....
<TD id='tag2'></TD>
http://www.webchemie.nl
|
|
Reply By:
|
joefawcett
|
Reply Date:
|
9/16/2006 5:15:31 AM
|
var vtag = document.getElementById("tag" + results[0]);
if (vtag) vtag.innerHTML = results[1]
--
Joe (Microsoft MVP - XML)
|
|
Reply By:
|
incredi-man
|
Reply Date:
|
9/16/2006 11:46:20 AM
|
Thanks Joe for your quick respons, you helped me a great deal! I only had to add a trim function, and it works like a buzz now!
function trim(str) { return str.replace(/^\s*|\s*$/g,""); }
function handleHttpResponse() { if (http.readyState == 4) { // Put returned values in array results = http.responseText.split("|"); // construct variable en assign value to it var vtag = document.getElementById("tag" + trim(results[0])); if (vtag) vtag.innerHTML = results[1] } }
http://www.webchemie.nl
|