Solved

Javascript -- inner HTML question

Posted on 2015-02-10
4
150 Views
Last Modified: 2015-02-10
Hi,

I'm setting the value of a <DIV> using Javascript. Once the value is set, I would like to retrieve it. But when I try using this code all I get is "undefined" in my alert. Could someone help me out here?
Thanks!
Mike
 

var value=500
document.getElementById('aoy_cost').innerHTML = value;
var actor_cost = document.getElementById('aoy_cost').value;
alert(actor_cost);
0
Comment
Question by:nachtmsk
  • 2
4 Comments
 
LVL 44

Accepted Solution

by:
Rainer Jeschor earned 500 total points
ID: 40601295
Hi,
afaik the value property is just for form/input elements and not for divs. Have you tried to retrieve the innerHTML of the div?
HTH
Rainer
0
 

Author Comment

by:nachtmsk
ID: 40601319
Thanks, that's what I needed to know.
var value=500
document.getElementById('aoy_cost').innerHTML = value;
var actor_cost = document.getElementById('aoy_cost').innerHTML ;
alert(actor_cost);
0
 
LVL 53

Expert Comment

by:COBOLdinosaur
ID: 40601330
This line is trying to reference what?
var actor_cost = document.getElementById('aoy_cost').value;
There is no such property defined in the script you posted, and it is not a default property.

If you are trying to get the value of some element that is part of what you put in the innerHTML, the you need to reference the element by name or id.

Cd&
0
 
LVL 53

Expert Comment

by:COBOLdinosaur
ID: 40601335
Ooops too slow again. ;^)

Cd&
0

Featured Post

What Should I Do With This Threat Intelligence?

Are you wondering if you actually need threat intelligence? The answer is yes. We explain the basics for creating useful threat intelligence.

Join & Write a Comment

Introduction HyperText Transfer Protocol (http://www.ietf.org/rfc/rfc2616.txt) or "HTTP" is the underpinning of internet communication.  As a teacher of web development I have heard many questions, mostly from my younger students who have come to t…
The Confluence of Individual Knowledge and the Collective Intelligence At this writing (summer 2013) the term API (http://dictionary.reference.com/browse/API?s=t) has made its way into the popular lexicon of the English language.  A few years ago, …
The viewer will learn the basics of jQuery, including how to invoke it on a web page. Reference your jQuery libraries: (CODE) Include your new external js/jQuery file: (CODE) Write your first lines of code to setup your site for jQuery.: (CODE)
The viewer will learn the basics of jQuery including how to code hide show and toggles. Reference your jQuery libraries: (CODE) Include your new external js/jQuery file: (CODE) Write your first lines of code to setup your site for jQuery…

707 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

Need Help in Real-Time?

Connect with top rated Experts

12 Experts available now in Live!

Get 1:1 Help Now