• Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 5875
  • Last Modified:

how to add the text for the div tag from javascript

Hi,

  How to add the text to the <div> tag from java script

for example in html:

<html>
<script language="javascript">
function fndiv()
{
   var objElement = document.getElementById("myDiv");
   objElement.style.visibility = "visible";
   objElement.value = "new value";
}
</script>
<body onload="fndiv()">
<form id="frm1">
<div id="myDiv" style="VISIBILITY: hidden; POSITION: absolute">this is txt</div>
</form>
</body>
</html>

but the above code is not able to set the text value in div tag

pls suggest how to set the value of the div tag from javascript
or give me some sample code

thanx
0
mohan21_kumar
Asked:
mohan21_kumar
1 Solution
 
wesbirdCommented:
Its this:    objElement.innerHTML = "new value";



<html>
<script language="javascript">
function fndiv()
{
   var objElement = document.getElementById("myDiv");
   objElement.style.visibility = "visible";
   objElement.innerHTML = "new value";
}
</script>
<body onload="fndiv()">
<form id="frm1">
<div id="myDiv" style="VISIBILITY: hidden; POSITION: absolute">this is txt</div>
</form>
</body>
</html>
0
 
mlpk_tyrCommented:
hi,
or alternative you can set a variable that stores some variable on load and you can reset on the functional call. by this you can achieve the same.

<html>
<script language="javascript">
function fndiv()
{
   var objElement = document.getElementById("myDiv");
   objElement.style.visibility = "visible";
   //objElement.innerHTML = "new value";
   var val ="my text which goes into the div tag";
}
</script>
<body onload="fndiv()">
<form id="frm1">
<div id="myDiv" style="VISIBILITY: hidden; POSITION: absolute">
<script language="javascript"> document.write(val);</script>
</div>
</form>
</body>
</html>


hope this works,
mlpk_tyr
0

Featured Post

VIDEO: THE CONCERTO CLOUD FOR HEALTHCARE

Modern healthcare requires a modern cloud. View this brief video to understand how the Concerto Cloud for Healthcare can help your organization.

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