Hello and welcome to our community! Is this your first visit?
Register
Enjoy an ad free experience by logging in. Not a member yet? Register.
Results 1 to 5 of 5
  1. #1
    New to the CF scene
    Join Date
    Apr 2004
    Posts
    6
    Thanks
    0
    Thanked 0 Times in 0 Posts

    getElementById mix variable with string

    Here is my code
    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?

  • #2
    Supreme Master coder! abduraooft's Avatar
    Join Date
    Mar 2007
    Location
    N/A
    Posts
    14,865
    Thanks
    160
    Thanked 2,224 Times in 2,211 Posts
    var tmp_field = getElementById(copy_from).value;
    Should be
    Code:
    var tmp_field = document.getElementById(copy_from).value;
    The Dream is not what you see in sleep; Dream is the thing which doesn't let you sleep. --(Dr. APJ. Abdul Kalam)

  • #3
    New to the CF scene
    Join Date
    Apr 2004
    Posts
    6
    Thanks
    0
    Thanked 0 Times in 0 Posts
    Quote Originally Posted by abduraooft View Post
    Should be
    Code:
    var tmp_field = document.getElementById(copy_from).value;
    Definitely was missing the document. but getting
    Code:
    document.getElementById(copy_from) is null

  • #4
    Regular Coder
    Join Date
    Jan 2006
    Posts
    568
    Thanks
    6
    Thanked 84 Times in 84 Posts
    Code:
    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:

    Code:
    document.product[copy_from].value
    Last edited by gusblake; 12-12-2009 at 12:46 AM.

  • #5
    Supreme Master coder! abduraooft's Avatar
    Join Date
    Mar 2007
    Location
    N/A
    Posts
    14,865
    Thanks
    160
    Thanked 2,224 Times in 2,211 Posts
    Quote Originally Posted by rob897 View Post
    Definitely was missing the document. but getting
    Code:
    document.getElementById(copy_from) is null
    Please post your relevant html too.
    The Dream is not what you see in sleep; Dream is the thing which doesn't let you sleep. --(Dr. APJ. Abdul Kalam)


  •  

    Posting Permissions

    • You may not post new threads
    • You may not post replies
    • You may not post attachments
    • You may not edit your posts
    •