Go Back   CodingForums.com > :: Client side development > JavaScript programming

Before you post, read our: Rules & Posting Guidelines

Reply
 
Thread Tools Rate Thread
Enjoy an ad free experience by logging in. Not a member yet? Register.
Old 01-21-2012, 04:40 PM   PM User | #1
anonymous9
New Coder

 
Join Date: Jan 2012
Posts: 37
Thanks: 1
Thanked 0 Times in 0 Posts
anonymous9 is an unknown quantity at this point
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 05:36 PM..
anonymous9 is offline   Reply With Quote
Old 01-21-2012, 06:18 PM   PM User | #2
Philip M
Supreme Master coder!

 
Philip M's Avatar
 
Join Date: Jun 2002
Location: London, England
Posts: 17,098
Thanks: 197
Thanked 2,421 Times in 2,399 Posts
Philip M has a spectacular aura aboutPhilip M has a spectacular aura aboutPhilip M has a spectacular aura about
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?


Code:
<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")

</script>
All advice is supplied packaged by intellectual weight, and not by volume. Contents may settle slightly in transit.
__________________

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.

Last edited by Philip M; 01-21-2012 at 06:22 PM..
Philip M is offline   Reply With Quote
Reply

Bookmarks

Jump To Top of Thread


Thread Tools
Rate This Thread
Rate This Thread:

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off

Forum Jump


All times are GMT +1. The time now is 06:54 AM.


Advertisement
Log in to turn off these ads.