Solved

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

Posted on 2006-12-01
8
333 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
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
VIDEO: THE CONCERTO CLOUD FOR HEALTHCARE

Modern healthcare requires a modern cloud. View this brief video to understand how the Concerto Cloud for Healthcare can help your organization.

 
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

Don't Cry: How Liquid Web is Ensuring Security

WannaCry is just the start. Read how Liquid Web is protecting itself and its customers against new threats.

Question has a verified solution.

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

When the s#!t hits the fan, you don’t have time to look up who’s on call, draft emails, call collaborators, or send text messages. An instant chat window is definitely the way to go, especially one like HipChat. HipChat is a true business app. An…
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 reset a WordPress password if you are locked out and cannot reset the password. A typical use would be if you cannot access the email to which WordPress would send the password recovery email to…
The purpose of this video is to demonstrate how to integrate Mailchimp with WordPress, by placing a Mailchimp signup form on a WordPress Page or Post. This will be demonstrated using a Windows 8 PC. Mailchimp will be used. Log into your Mailchi…

615 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