www.webdeveloper.com
Results 1 to 5 of 5

Thread: Javascript to count the number of times an alert box is triggered

  1. #1
    Join Date
    Jan 2007
    Posts
    78

    Javascript to count the number of times an alert box is triggered

    I have a search field that allows for searching a text file. If the entry is NOT formatted correctly, an alert is displayed. They only get to see the submit button if the field is correctly formatted.

    What I want to do is to limit the number of times they can try to 4 attempts.

    How can I set a cookie in javascript to get the users IP address, and count the number of times the alert box is triggered by them in that 1 session, and after the 4 triggered attempts, display a message ( TELL THEM TO GO AWAY! ) and disable the input field for users from that IP address for 1 hour.

    The input field is like this.

    Code:
    <input type="text" name="codenumber"   maxlength="16" size="16"onMouseOut="checkAlert()";/>
    How do I code the cookie etc...etc... OR is there a better way to accomplish this.

    Maybe I can hide the input field in a DIV and check to see if that IP is banned before showing it.
    I have never set cookies to do any of this before.

    I DON'T want to have to go the server route & PHP if I don't have to.

    Thanks

  2. #2
    Join Date
    Jan 2007
    Posts
    78
    In case anyone else wanted.
    This is how you can check the number of times an alert is triggered.
    Not pretty & professional, but it worked for what I needed.

    Code:
    <script type="text/javascript"> 
    var i=0;
     
    function increase()
     
    {
    	i++;
    	
     
    alert("I am alert box number"    + ' '+   (i));  
     
     //check if we should kick them out
     
        if (i> 4) {
     
            //two plus signs will increment our variable by one
     
    	alert("Please Go Away ! You have been warned");
    	
    	self.close();
            
        		} 
      
     
    }
     
    </script>
     
    <input type="button" Value=" Click Me To Increment"  onclick="increase();">

  3. #3
    Join Date
    May 2006
    Location
    Somewhere behind your screen
    Posts
    1,672
    self.close() is too much cruel. i'd better redirect them to, for example, http : // xhamster . com / channels / new-gays-1 . html

  4. #4
    Join Date
    Jan 2007
    Posts
    78
    Padonak:

    You may be right!

  5. #5
    Join Date
    May 2006
    Location
    Somewhere behind your screen
    Posts
    1,672
    rofl )))))))))

Thread Information

Users Browsing this Thread

There are currently 1 users browsing this thread. (0 members and 1 guests)

Posting Permissions

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



Recent Articles