Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Chris Miller on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

setting document.body.outerText WITHIN onload?

Status
Not open for further replies.

Rex868

Programmer
Dec 19, 2007
3
US
Hi All - JavaScript newbie here. Any idea why the following always shows "aaa" in the web page AND the 2nd alert does not occur?
<html>
<head>
</head>

<script type="text/javascript" language="javascript">
function myTest() {
alert (document.body.outerText);
document.body.outerText = "bbb";
alert (document.body.outerText);
}
</script>

<body onload="myTest()";>
aaa
</body>
</html>
 
Try innerText, outerText replaces the whole element so it's throwing an error.

Cheers,
Dian
 
Very good, Dian. That (almost) solved my problem. That did indeed allow me to update the text found within the Body tag - and that is great - so thanks! However, I'm now experiencing another issue. Basically, I've trying to READ what's in the Body area - and then manipulate it - and then write the revised version back out. The PROBLEM I'm now having is that some of what I'm reading is data found in within a Form area, and apparently when this occurs, the Form labels are there but NOT the (pre-filled) DATA. Do you or anyone know how I might be able to (pause or whatever?) to get the data also? Thanks,
Rex
 
The inner* properties returns the page as it's served, not he content you put there afterwards.

Cheers,
Dian
 
Hi Dian - I see your point. Actually I now realize I was incorrect. It turns out that the DATA is indeed there, but is found as an attribute of an INPUT tag. So innerText worked fine - What I need is innerHTML - so my problem is solved and thanks very much, Dian!
Rex
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top