473,320 Members | 2,048 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,320 software developers and data experts.

updating values with getelementsbyid

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:

Expand|Select|Wrap|Line Numbers
  1. function text(t)
  2.     {
  3.       return document.createTextNode(t);
  4.     }
  5. function start(){
  6.  
  7. var oHelloText = text(getQuestion()); //the getQuestion method returns a string from an array
  8.         oHelloText.id = "test";
  9. }
  10.  
  11. function updateDetails()
  12.     {
  13.         document.getElementById('test') = text(getQuestion());           
  14.     }
  15.  
//sometime later, call to updateDetails method.

Unsurprisingly, this doesn’t work.

Any advice?
Nov 8 '07 #1
3 1780
gits
5,390 Expert Mod 4TB
hi ...

as far as i can see you create a textnode from a string. but with that you cannot do:

Expand|Select|Wrap|Line Numbers
  1. document.getElementById('test') = text(getQuestion());
you cannot work with dom-nodes that way i think. you simply could do:

Expand|Select|Wrap|Line Numbers
  1. document.getElementById('test').value = 'your_text';
or you should have a look at the replaceChild() method ... the text of your element to replace is a textnode with a textvalue itself ... so you have to replace it accordingly ...

kind regards
Nov 8 '07 #2
I see.

I went a layer up and gave the id to my P, which contains the text node.

I then wrote this (where 'test' now refers to the holder of the text node).

Expand|Select|Wrap|Line Numbers
  1. function updateDetails()
  2.     {
  3.         var zzz = (document.getElementById('test'));
  4.         zzz.removeChild(zzz.firstChild);
  5.         zzz.appendChild(text(getQuestion()));
  6.  
  7.     }
This works, but doesn't seem very efficient. Is there a more suitable way?
Nov 8 '07 #3
gits
5,390 Expert Mod 4TB
hi ...

why do you use the complex textNode-way? you could set the value ... is there any reason that deserves the node-way for you?

btw: please use code-tags when posting source code ...

kind regards
Nov 8 '07 #4

Sign in to post your reply or Sign up for a free account.

Similar topics

11
by: Jason | last post by:
Let's say I have an html form with 20 or 30 fields in it. The form submits the fields via POST to a php page which updates a table in a database with the $_POST vars. Which makes more sense? ...
1
by: Abdullah Kauchali | last post by:
Hi folks, I am currently getting/setting values in an HTML table with: document.getElementById(id).childNodes.nodeValue where "id" is the id of the <td> tag of the cell. This works,...
7
by: Carl | last post by:
Hi I have a form that requires the user to enter a tenancy reference number in the first column, and when this is done it brings back their direct debit payment for their rent in the second column...
4
by: Darrel | last post by:
I'm creating a table that contains multiple records pulled out of the database. I'm building the table myself and passing it to the page since the table needs to be fairly customized (ie, a...
1
by: Luis Esteban Valencia | last post by:
Hello Everyone, Iam an intermediate ASP.Net programmer and iam facing a challenging task. I have a table in MS-SQL server database called 'Members'. The table has following fields... ...
10
by: jaYPee | last post by:
does anyone experienced slowness when updating a dataset using AcceptChanges? when calling this code it takes many seconds to update the database SqlDataAdapter1.Update(DsStudentCourse1)...
4
by: Geoff | last post by:
Hi I'm hoping somebody can help me with the following problem that has occurred to me. Suppose I have two tables in an SQL Server database. Let's call these tables A and B. Assume that A has...
33
by: bill | last post by:
In an application I am writing the user can define a series of steps to be followed. I save them in a sql database using the field "order" (a smallint) as the primary key. (there are in the range...
3
by: jags | last post by:
Hi All I could not display my image through this getElementsById(ImgName).Please let me what is wrong with this piece of code .I have stored all my images in the Doclib of sharepoint site.The...
0
by: DolphinDB | last post by:
The formulas of 101 quantitative trading alphas used by WorldQuant were presented in the paper 101 Formulaic Alphas. However, some formulas are complex, leading to challenges in calculation. Take...
0
by: DolphinDB | last post by:
Tired of spending countless mintues downsampling your data? Look no further! In this article, you’ll learn how to efficiently downsample 6.48 billion high-frequency records to 61 million...
0
by: Vimpel783 | last post by:
Hello! Guys, I found this code on the Internet, but I need to modify it a little. It works well, the problem is this: Data is sent from only one cell, in this case B5, but it is necessary that data...
0
by: ArrayDB | last post by:
The error message I've encountered is; ERROR:root:Error generating model response: exception: access violation writing 0x0000000000005140, which seems to be indicative of an access violation...
1
by: PapaRatzi | last post by:
Hello, I am teaching myself MS Access forms design and Visual Basic. I've created a table to capture a list of Top 30 singles and forms to capture new entries. The final step is a form (unbound)...
0
by: CloudSolutions | last post by:
Introduction: For many beginners and individual users, requiring a credit card and email registration may pose a barrier when starting to use cloud servers. However, some cloud server providers now...
0
by: Defcon1945 | last post by:
I'm trying to learn Python using Pycharm but import shutil doesn't work
0
by: af34tf | last post by:
Hi Guys, I have a domain whose name is BytesLimited.com, and I want to sell it. Does anyone know about platforms that allow me to list my domain in auction for free. Thank you
0
by: Faith0G | last post by:
I am starting a new it consulting business and it's been a while since I setup a new website. Is wordpress still the best web based software for hosting a 5 page website? The webpages will be...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.