Wrox Programmer Forums
|
Javascript How-To Ask your "How do I do this with Javascript?" questions here.
Welcome to the p2p.wrox.com Forums.

You are currently viewing the Javascript How-To 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 November 8th, 2007, 11:07 AM
Registered User
 
Join Date: Nov 2007
Posts: 8
Thanks: 0
Thanked 0 Times in 0 Posts
Default updating values

Hi everyone,

I am trying to update the value which is stored in a particular part of my page by using the getElementsById method, followed by calling a function to update the field. However, I don’t know how to do this. The relevant parts of my code are as follows:


function text(t)
    {
      return document.createTextNode(t);
    }
function start(){

var oHelloText = text(getQuestion()); //the getQuestion method returns a string from an array
        oHelloText.id = "test";
}

function updateDetails()
    {
        document.getElementById('test') = text(getQuestion());
    }

//sometime later, call to updateDetails method.

Unsurprisingly, this doesn’t work.

Any advice?


 
Old November 26th, 2007, 01:34 PM
Friend of Wrox
 
Join Date: Feb 2007
Posts: 163
Thanks: 0
Thanked 2 Times in 2 Posts
Default

Your updateDetails function is creating a new object with the id of 'test' that will contain the new data and NOT replacing the data in the original object created with the id of 'test'. Instead you need to retrieve the object and change it's value.

Other things to consider:
Do you have other objects that have the id of 'test'? The document.getElementByID only retrieves the first instance.

If there is only one object with the id of 'test' and you're no longer calling the create sub to update but it's still not working right then try making it's name parameter the same as it's id parameter.

Remember that if this function is called more than once then you will have more than 1 instance of an object with 'test' as the id.

With more than 1 object being named you would want to use the getElementsByName command to return an array of objects with that name parameter. How you identify them separately to update the correct instance is up to you.

Does this help point you in the right direction?






Similar Threads
Thread Thread Starter Forum Replies Last Post
Updating Bound Controls Values automatically Borhani Excel VBA 0 January 20th, 2008 12:48 PM
get the values of form field values crmpicco Perl 2 March 16th, 2007 10:57 AM
Simple Databinding to Datarow, values not updating TheTinSoldier C# 0 February 7th, 2007 04:29 PM
Updating boolean values using datalist Scripts82 ASP.NET 1.0 and 1.1 Basics 1 September 20th, 2006 04:17 AM
loop values and text box values move mateenmohd Classic ASP Basics 2 April 5th, 2005 11:33 PM





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