javascript - How do I send all window alerts to one text box -


i had assignment used window alerts user knew happening in game. have got update game different assignment time window alerts have go text box. text box has "click on selection" base text. how make window alerts overwrite text?

the code below have window alerts:

function check(guess) {     if (diamond == guess) {         window.alert("congratulations! have found diamond.")         again = window.prompt("would play game? enter y or n.", "y");         if (again == "n" || again == "n") {             window.alert("thanks playing.goodbye.");             window.close();         } else {             window.alert("the diamond has been hidden. can try again.");             window.location.reload();         }     } else {         number_of_guesses = number_of_guesses + 1;         if (diamond < guess) {             result = "lower"         } else {             result = "higher"         }         window.alert("guess number " + number_of_guesses + " incorrect. diamond " + result + ".");     }     if (number_of_guesses >= 3) {         window.alert("sorry, have run out of guesses! diamond in box " + diamond);         again = window.prompt("would play again? enter y or n. ", "y");         if (again == "n" || again == "n") {             window.alert("thanks playing. goodbye.");             window.close();         } else {             window.alert("the diamond has been hidden. can try again.");             window.location.reload();         }     } } 

i put window alerts 1 text box:

<input type="text" id="windowalerts" name="windowalerts" value= "click on selection " size=30>  

can please tell me how can this?

one simple ways can directly overwrite window's alert function in javascript, , inside overwritten function textbox's id , add value of alert there... e.g.

<input type="text" id="mytextbox"/> window.alert = function(message) {     document.getelementbyid('mytextbox').value = message; } 

here fiddle try


Comments

Popular posts from this blog

ios - RestKit 0.20 — CoreData: error: Failed to call designated initializer on NSManagedObject class (again) -

java - Digest auth with Spring Security using javaconfig -

laravel - PDOException in Connector.php line 55: SQLSTATE[HY000] [1045] Access denied for user 'root'@'localhost' (using password: YES) -