www.webdeveloper.com
Results 1 to 2 of 2

Thread: change string to var name

  1. #1
    Join Date
    Sep 2008
    Location
    Harrisonburg, VA
    Posts
    151

    change string to var name

    I am passing a string that happens to be a div name to my JS function and in my JS there is a variable with the same name as the string. I want to access that variable based on the div name that is passed.

    Code:
    var findMe;
    
    findMe = "Test, Test, Test, Test";
    
    function getText(toGet)
    {
    	alert(toGet.toString());
    	var toReturn = toGet.toString(); //This sets toReturn to "findMe" I want it to set it as the value of findMe
    	return toReturn;
    }

  2. #2
    Join Date
    Jul 2008
    Location
    urbana, il
    Posts
    2,787
    you must be calling it like: getText("findMe"), when you want getText(findMe)...

Thread Information

Users Browsing this Thread

There are currently 1 users browsing this thread. (0 members and 1 guests)

Posting Permissions

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



Recent Articles