View Full Version : Tracking How Many Times User Hit OK Button

01-21-2012, 05:40 PM
How would I track how many times a user hit the OK button when prompted with a message using document.writeln?

Philip M
01-21-2012, 07:18 PM
Sorry, I don't understand. document.write() will over-write the whole content of the page, including the JavaScript which called it.

If you mean a prompt dialogue then the answer must be 1 - clicking on OK terminates the dialogue and runs whatever code follows.

Or do you mean something like this? That is, count the number of invalid entries?

<script type = "text/javascript">

var count = 0;
for (var i=1; i<2; i++) {
var ans = parseFloat(prompt ("Enter a number", ""));
count ++;
if ((isNaN(ans)) || (ans == "")) {
alert ("You must enter a number!! ");
i -- ;

alert ("You had " + count + " tries")

All advice is supplied packaged by intellectual weight, and not by volume. Contents may settle slightly in transit.