Wrox Programmer Forums
Javascript General Javascript discussions.
Welcome to the p2p.wrox.com Forums.

You are currently viewing the Javascript section of the Wrox Programmer to Programmer discussions. This is a community of software programmers and website developers including Wrox book authors and readers. New member registration was closed in 2019. New posts were shut off and the site was archived into this static format as of October 1, 2020. If you require technical support for a Wrox book please contact http://hub.wiley.com
Old September 16th, 2006, 03:39 AM
Registered User
Join Date: Sep 2006
Posts: 3
Thanks: 0
Thanked 0 Times in 0 Posts
Default var as variable

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>

Old September 16th, 2006, 05:15 AM
joefawcett's Avatar
Wrox Author
Join Date: Jun 2003
Posts: 3,074
Thanks: 1
Thanked 38 Times in 37 Posts

var vtag = document.getElementById("tag" + results[0]);
if (vtag) vtag.innerHTML = results[1]

Joe (Microsoft MVP - XML)
Old September 16th, 2006, 11:46 AM
Registered User
Join Date: Sep 2006
Posts: 3
Thanks: 0
Thanked 0 Times in 0 Posts

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]


Similar Threads
Thread Thread Starter Forum Replies Last Post
var,text ,..... angelboy SQL Language 2 May 29th, 2007 11:37 AM
"Out of scope" var??? yankleber XSLT 2 March 31st, 2007 03:53 AM
Using a var into the name of another var or field. guizero Access VBA 3 May 30th, 2006 03:47 PM
Dissapearing VAR topshed Classic ASP Databases 5 June 3rd, 2005 01:34 PM
Temp Var in For Each pbernardo XSLT 5 November 14th, 2003 06:45 PM

Powered by vBulletin®
Copyright ©2000 - 2020, Jelsoft Enterprises Ltd.
Copyright (c) 2020 John Wiley & Sons, Inc.