Solved

Javascript -- inner HTML question

Posted on 2015-02-10
4
156 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

Use Case: Protecting a Hybrid Cloud Infrastructure

Microsoft Azure is rapidly becoming the norm in dynamic IT environments. This document describes the challenges that organizations face when protecting data in a hybrid cloud IT environment and presents a use case to demonstrate how Acronis Backup protects all data.

Question has a verified solution.

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

Suggested Solutions

This article will give core knowledge of JavaScript and will head in to your first JavaScript program. I am Durvesh Naik and I am here to deal with this series of JavaScript. I will teach you JavaScript in part wise , as its quite boring to read big…
JavaScript can be used in a browser to change parts of a webpage dynamically. It begins with the following pattern: If condition W is true, do thing X to target Y after event Z. Below are some tips and tricks to help you get started with JavaScript …
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…

777 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