Korne127 Korne127 - 4 months ago 9
HTML Question

How to delete the texts and formulars on the site

I have two questions but, as they are so similar, I ask it as one question:

Question 1:

I have made text and a formular with html. If somebody klicks on one button, all text must vanish. Here is my code:

Hello here is example text
<form action="example.php" method="POST">
First name:
<input type="Text" name="Name" size="50" placeholder="First Name" maxlength="20"><br>
Last Name:
<input type="Text" name="LName" size="50" placeholder="Last Name" maxlength="200"><br>
<input type="Submit" value="Register">
<br><br><br><br><br>
Delete all:
<button onclick="Delete()">Make all Vanish!</button>


function Delete() {
//Here comes the code to vanish the formular, the text and the button itselve!

}









The second question is really easy. Is there a possibility to make not only formulars and server-based text but also javascript text (I mean)

<script>
document.write("Here is the javascript text");
</script>


vanish?
To see what I mean, here comes the full code:




Hello here is example text<br>
<script>
document.write("And here is some javascript text");
</script><br>

<form action="example.php" method="POST">
First name:
<input type="Text" name="Name" size="50" placeholder="First Name" maxlength="20"><br>
Last Name:
<input type="Text" name="LName" size="50" placeholder="Last Name" maxlength="200"><br>
<input type="Submit" value="Register">
<br><br><br><br><br>
Delete all:
<button onclick="Delete()">Make all Vanish!</button>

function Delete() {
//Here comes the code to vanish the formular, the HTML or PHP text and the //button itselve!

//Here comes the code to vanish the javascript text (or the best way would be //one code to vanish all)

}

Answer

There is no way to identify what text is added by document.write and the one that is written in your html file.

Your both the questions basically needs this line to be added in your Delete() function

document.getElementsByTagName('body')[0].innerHTML = ''

Which obviously also makes the whole body empty.

I will suggest to have wrapper divs around your code structure which can help in demarcation.