Solved

Updating a html ID with a document.all. htmlID .value via a javascript

Posted on 2006-12-01
8
324 Views
Last Modified: 2013-12-16

i am updating a html ID with a document.all.htmlID.value via a javascript.
i can hard code the htmlID and update the value but in this case the html id is dynamic and changes for variables.  

here is the scenario...
note: document.all.html_tag is a variable, and document.all.Price235
this doesnt work...
====================================
var html_tag = "Price" + items[itemCount].getAttribute("ID");
//html_tag = "Price235"
if (document.all.html_tag.value)
      document.all.html_tag.value = this.GetFormattedAttributeValue(items[itemCount], "Price");
                  
this works and updates my webpage buts its hardcoded.
====================================
var html_tag = "Price" + items[itemCount].getAttribute("ID");
if (document.all.html_tag.value)
      document.all.Price235.value = this.GetFormattedAttributeValue(items[itemCount], "Price");
0
Comment
Question by:mploschiavo
8 Comments
 
LVL 6

Expert Comment

by:davbouchard
ID: 18055157
Have you tried using
document.getElementById("Price" + items[itemCount].getAttribute("ID")).value = this.GetFormattedAttributeValue(items[itemCount], "Price");
0
 
LVL 2

Author Comment

by:mploschiavo
ID: 18055302
i cant seem to get that to work... i get a
error: document.getElementById(...) is null or not an object
0
 
LVL 2

Author Comment

by:mploschiavo
ID: 18055407
this doesnt work either....  

eval("document.all."+html_tag+".value") = this.GetFormattedAttributeValue(items[itemCount], "Price");
0
Microsoft Certification Exam 74-409

Veeam® is happy to provide the Microsoft community with a study guide prepared by MVP and MCT, Orin Thomas. This guide will take you through each of the exam objectives, helping you to prepare for and pass the examination.

 
LVL 18

Expert Comment

by:Morcalavin
ID: 18055544
Try
document.all[html_tag].value
0
 
LVL 1

Accepted Solution

by:
gprina earned 500 total points
ID: 18055872
Well... it's a really old syntax, and it doesn't work for me in the latest versions (I don't know which version of IE or Firefox you are using), but if the second portion of code (the one hardcoded) it's working for you please try this:

eval("document.all."+html_tag).value = this.GetFormattedAttributeValue(items[itemCount], "Price");

I just placed the "value" outside the eval, because you just need to obtain the object.

Double check that you also change the previous IF and also check that html_tag contains the right value.
0
 
LVL 2

Author Comment

by:mploschiavo
ID: 18056660
thanks gprina
i got it to work .... works on ie6...  since its old syntax... is there a better way?

if (items[itemCount].getAttribute("ID"))
                  {      if ( eval("document.all."+"Price" + items[itemCount].getAttribute("ID")) != null )
                              eval("document.all."+"Price" + items[itemCount].getAttribute("ID")).value = this.GetFormattedAttributeValue(items[itemCount], "Price");

0
 
LVL 1

Expert Comment

by:gprina
ID: 18056678
Check this out:

if (items[itemCount].getAttribute("ID"))
               {
                 var obj = eval("document.all."+"Price" + items[itemCount].getAttribute("ID"));
                 if ( obj  != null )
                         obj.value = this.GetFormattedAttributeValue(items[itemCount], "Price");
0
 
LVL 1

Expert Comment

by:gprina
ID: 18056693
Ops... I may be missinterpreted your last question, but if

  document.getElementById(html_tag).value = this.GetFormattedAttributeValue(items[itemCount], "Price");

no, I think there is no a better syntax for IE6
0

Featured Post

Gigs: Get Your Project Delivered by an Expert

Select from freelancers specializing in everything from database administration to programming, who have proven themselves as experts in their field. Hire the best, collaborate easily, pay securely and get projects done right.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

Get to know the ins and outs of building a web-based ERP system for your enterprise. Development timeline, technology, and costs outlined.
This article will inform Clients about common and important expectations from the freelancers (Experts) who are looking at your Gig.
The purpose of this video is to demonstrate how to update a WordPress Site’s version. WordPress releases new versions of its software frequently and it is important to update frequently in order to keep your site secure, and to get new WordPress…
The purpose of this video is to demonstrate how to prevent comment spam on a WordPress Website. This will be demonstrated using a Windows 8 PC. Plugin Akismet will be used. Go to your WordPress login page. This will look like the following: myw…

776 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question