...

View Full Version : getElementById mix variable with string



rob897
12-11-2009, 03:51 PM
Here is my code


function copy_grid(from,to)
{
var copy_from = from +"_24_product_cost"; // in this instance from = grid1_White
var copy_to = to;
var tmp_field = getElementById(copy_from).value; // ERROR: getElementById is not defined
}


document.product.grid1_White_24_product_cost.value // works as expected
but I wanted this to be dynamic.

Any ideas?

abduraooft
12-11-2009, 03:59 PM
var tmp_field = getElementById(copy_from).value; Should be

var tmp_field = document.getElementById(copy_from).value;

rob897
12-11-2009, 04:16 PM
Should be

var tmp_field = document.getElementById(copy_from).value;

Definitely was missing the document. but getting

document.getElementById(copy_from) is null

gusblake
12-11-2009, 11:43 PM
document.product.grid1_White_24_product_cost.value

Is it the name or the id? document.getElementById won't pick up a name, but if it is in the name then this will work dynamically:


document.product[copy_from].value

abduraooft
12-12-2009, 07:03 AM
Definitely was missing the document. but getting

document.getElementById(copy_from) is nullPlease post your relevant html too.



EZ Archive Ads Plugin for vBulletin Copyright 2006 Computer Help Forum