1

I have basically created a table that is made of two rows, the first row checks if the user input is correct or not, and the second row is displaying a button. I have used the following code inside my script function inside the first row of my table to display the output response:

function checkUserInput() {
var userInput = document.getElementById("textInput").value;
var stringToCheckAgainst = random_images_array[num].split('.');
//this splits the item at the array index into an array, like so. 
If the item is "apple.gif", the array reads ["apple", "gif"]
if (userInput == stringToCheckAgainst[0]) {
//user has inputted the correct string
//window.alert("user gave correct response!");
document.write("<p>" + txt.fontsize(5) + "</p>"); document.close();

} else {
//user has inputted an incorrect string
//window.alert("user gave incorrect response!");
document.write("<p>" + txt1.fontsize(5) + "</p>"); document.close(); 
}
}
</script>

However this code will delete the entire page (document). Can anyone advise me how to write the message only the top section of my page (or table) and leave the second row of my table unchanged?

Alan
  • 11
  • 3
  • possible duplicate of [document.write() overwriting the document?](http://stackoverflow.com/questions/19941866/document-write-overwriting-the-document) – showdev Jul 22 '15 at 17:25
  • this is diffrent actually as i am using the script for a part of my table. how should i give id to the first row?! – Alan Jul 22 '15 at 17:35
  • 2
    You may want to show of your code to illustrate your context. It's not clear what exactly you're trying to accomplish. – showdev Jul 22 '15 at 17:36
  • instead of writing to document, write to something else? The first comment looks like exactly what you want. – RisingSun Jul 22 '15 at 17:43
  • if you have a id on your table you can use something like document.getElementById('id').innerHTML = 'replacement text'; – ydobonebi Jul 22 '15 at 17:44

0 Answers0