Win a copy of Re-engineering Legacy Software this week in the Refactoring forum
or Docker in Action in the Cloud/Virtualization forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

access javascript DOM object value from HTML

 
mark I thomas
Ranch Hand
Posts: 86
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I have a html page that includes lot of javascript. In a portion of the html, I was trying to create some html content that needs to get the value of some DOM object. For example, I want to do somthing like
*********
<script type="text/javascript" ..."some javascript" ...></script>
....
....


The name is --
<!-- want to print value of this.myBox.name -->


********
"myBox" is an object defined in "some javascript" that the current HTML includes. Of course at the point where we create

the "myBox" is already created and has its value. The dilemma is I know how to access this value inside another javascript code snippet, but how do I get that value in my html ?

 
Eric Pascarello
author
Rancher
Posts: 15385
6
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
can you show us some actual code? Maybe create a small example that illustrates what you are trying to do.

Eric
 
mark I thomas
Ranch Hand
Posts: 86
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
In test.js:

**********
function Mybox() {
this.name = "test";
....
....


}

function alterName(e) {

this.mybox.name = e.value;
}
**********

In test.html:

<script type="text/javascript" src="test.js"/>

<body>

<div>
The box name is

<!-- try to access mybox.name value and append it here !! -->
</div>

</body>

**************

 
Bear Bibeault
Author and ninkuma
Marshal
Pie
Posts: 64629
86
IntelliJ IDE Java jQuery Mac Mac OS X
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Please UseCodeTags.
 
mark I thomas
Ranch Hand
Posts: 86
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
In test.js:

**********

**************



 
Bear Bibeault
Author and ninkuma
Marshal
Pie
Posts: 64629
86
IntelliJ IDE Java jQuery Mac Mac OS X
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Did you even look at your post after you made it? Does the code look any better? Please read on how to use code tags again. I have fixed the post for you this time.
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic