Solved

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

Posted on 2006-12-01
8
330 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
PeopleSoft Has Never Been Easier

PeopleSoft Adoption Made Smooth & Simple!

On-The-Job Training Is made Intuitive & Easy With WalkMe's On-Screen Guidance Tool.  Claim Your Free WalkMe Account Now

 
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

Secure Your WordPress Site: 5 Essential Approaches

WordPress is the web's most popular CMS, but its dominance also makes it a target for attackers. Our eBook will show you how to:

Prevent costly exploits of core and plugin vulnerabilities
Repel automated attacks
Lock down your dashboard, secure your code, and protect your users

Question has a verified solution.

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

Because your company can’t afford for you to make SEO mistakes, you’ll want to ensure you’re taking the right steps each and every time you post a new piece of content. This list of optimization do’s and don’ts can help you become an SEO wizard.
CTAs encourage people to do something specific to show interest in your company, product or service. Keep reading to learn why CTAs should always be thought of as extremely important, albeit small, sections of websites.
The purpose of this video is to demonstrate how to add AdSense Ads to a WordPress Website, and how to set up WordPress to automatically place Ads in Sidebars. This will be demonstrated using a Windows 8 PC. Log into your AdSense account. : Cli…
The viewer will learn how to create and use a small PHP class to apply a watermark to an image. This video shows the viewer the setup for the PHP watermark as well as important coding language. Continue to Part 2 to learn the core code used in creat…

751 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