...

View Full Version : clearbody() Function



soundreamer
01-26-2006, 09:46 PM
How to make a function that clears all text in body without clearing the one in the head (javascripts):)

vwphillips
01-26-2006, 10:00 PM
maybe

<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN"
"http://www.w3.org/TR/html4/loose.dtd">

<html>

<head>
<title></title>
<script language="JavaScript" type="text/javascript">
<!--

function Cal(selid,cbid,tbid){
var val=1;
if (document.getElementById(cbid).checked){
val=document.getElementById(cbid).value;
}
document.getElementById(tbid).firstChild.data=(document.getElementById(selid).value*val).toFixed(2);
document.getElementById(tbid+1).firstChild.data=document.getElementById(selid).value;
document.getElementById(tbid+2).firstChild.data=(document.getElementById(selid).value*val)-document.getElementById(selid).value;
}

function NoTxt(){
var bdy=document.getElementsByTagName('BODY')[0];
var eles=bdy.getElementsByTagName('*');
for (var zxc0 in eles){
nds=eles[zxc0].childNodes;
for (var zxc1 in nds){
if (nds[zxc1].nodeType==3){
nds[zxc1].parentNode.removeChild(nds[zxc1]);
}
}
}
}
//-->
</script></head>

<body >
<div>
1. Is there a way <div><div>to show a subtotal and</div></div> tax amount in addition to the total?

2. Is there a way to round decimals to two decimal places? For example 3000 + tax would be 268.13 instead of 268.125.

3. Is there a way to display numbers using standard paragraph tags instead of a text input box?
<select id="joe" onchange="Cal('joe','fred','tom');" >
<option value="10" >10 ddddddddd</option>
<option value="20" >20 ddddddddd</option>
<option value="30" >30 ddddddddd</option>
<option value="40" >40 ddddddddd</option>
</select>
<input id="fred" type="checkbox" value="1.1" onclick="Cal('joe','fred','tom');"><br>
subtotal <span id="tom1" >&nbsp;</span><br>
tax amount <span id="tom2" >&nbsp;</span><br>
total <span id="tom" >&nbsp;</span><br>
<input type="button" name="" value="Remove Text" onclick="NoTxt();"></body>
<script> vic=0; </script>
<form name=Show id=Show style="position:absolute;visibility:visible;top:450px;left:0px;" >
<input size=10 name=Show1 >
<input size=10 name=Show2 >
<input size=10 name=Show3 >
<input size=10 name=Show4 >
<input size=10 name=Show5 >
<input size=10 name=Show6 >
</form>
</div>
</html>

arnyinc
01-26-2006, 10:00 PM
<html>

<head>
<script language="javascript">
function clearBody(clearedElement){
clearedElement.innerHTML = '';
}
</script>
</head>

<body>

<input type="button" onclick="clearBody(document.body);" value="clear">

<table>
<tr><td>1asfqwfuihqweiofuhqweuiofh</td><td>1asfqwfuihqweiofuhqweuiofh</td><td>1asfqwfuihqweiofuhqweuiofh</td></tr>
<tr><td>1</td></tr>
<tr><td>1</td></tr>
</table>

</body>

</html>

liorean
01-26-2006, 10:13 PM
In browsers that support it, doing a shallow copy of the body element and replacing the original with the copy is probably the best performant way of doing it with W3C DOM. Or even replacing it with a newly created body element...

soundreamer
01-26-2006, 11:49 PM
Never mind... I tried this and it works perfectly...:thumbsup:


function clearbody () {
document.body.innerHTML="";
}



EZ Archive Ads Plugin for vBulletin Copyright 2006 Computer Help Forum