[Okta Webinar] Learn how to a build a cloud-first strategyRegister Now

x
  • Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 182
  • Last Modified:

Javascript -- inner HTML question

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
nachtmsk
Asked:
nachtmsk
  • 2
1 Solution
 
Rainer JeschorCommented:
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
 
nachtmskAuthor Commented:
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
 
COBOLdinosaurCommented:
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
 
COBOLdinosaurCommented:
Ooops too slow again. ;^)

Cd&
0

Featured Post

Free Tool: Path Explorer

An intuitive utility to help find the CSS path to UI elements on a webpage. These paths are used frequently in a variety of front-end development and QA automation tasks.

One of a set of tools we're offering as a way of saying thank you for being a part of the community.

  • 2
Tackle projects and never again get stuck behind a technical roadblock.
Join Now