Hello and welcome to our community! Is this your first visit?
Enjoy an ad free experience by logging in. Not a member yet? Register.
Results 1 to 2 of 2
  1. #1
    New Coder
    Join Date
    Jan 2012
    Thanked 0 Times in 0 Posts

    Tracking How Many Times User Hit OK Button

    How would I track how many times a user hit the OK button when prompted with a message using document.writeln?
    Last edited by anonymous9; 01-21-2012 at 06:36 PM.

  2. #2
    Supreme Master coder! Philip M's Avatar
    Join Date
    Jun 2002
    London, England
    Thanked 2,703 Times in 2,679 Posts
    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.
    Last edited by Philip M; 01-21-2012 at 07:22 PM.

    All the code given in this post has been tested and is intended to address the question asked.
    Unless stated otherwise it is not just a demonstration.


Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts