Go Premium for a chance to win a PS4. Enter to Win

x
?
Solved

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

Posted on 2006-12-01
8
Medium Priority
?
345 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
Technology Partners: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

 
LVL 18

Expert Comment

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

Accepted Solution

by:
gprina earned 2000 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

NEW Veeam Agent for Microsoft Windows

Backup and recover physical and cloud-based servers and workstations, as well as endpoint devices that belong to remote users. Avoid downtime and data loss quickly and easily for Windows-based physical or public cloud-based workloads!

Question has a verified solution.

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

When it comes to write a Context Sensitive Help (an online help that is obtained from a specific point in state of software to provide help with that state) ,  first we need to make the file that contains all topics, which are given exclusive IDs. …
When it comes to security, close monitoring is a must. According to WhiteHat Security annual report, a substantial number of all web applications are vulnerable always. Monitis offers a new product - fully-featured Website security monitoring and pr…
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 viewer will learn how to look for a specific file type in a local or remote server directory using PHP.
Suggested Courses

885 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