Forum Moderators: open

Message Too Old, No Replies

Alert on second document click...

         

JAB Creations

5:33 am on Mar 28, 2005 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



I'm trying to get an alert ONLY when the document recieves a second click. Right now I'm not getting anything to happen and no JS errors in FF or IE ironically enough!

var clickcount = 0;
var clickcycle = 2;
var clickspace = 2;
document.onclick = function()
{
clickcount = ++clickcount % clickcycle
if(clickcount &&!(clickcount % clickspace))
alert ('Alert');
}

Prolific

8:18 am on Mar 28, 2005 (gmt 0)

10+ Year Member



put: onclick="clickAlert();" in your body tag and use this:

var clickcount = 0;
var clickcycle = 2;

function clickAlert()
{
clickcount = ++clickcount
if(clickcount >= clickcycle)
alert ('alert');
}

birdbrain

8:25 am on Mar 28, 2005 (gmt 0)



Hi there JAB_Creations,

try it like this...

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" 
"http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
<html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en" lang="en">
<head>
<title>two clicks</title>

<meta http-equiv="Content-Type" content="application/xhtml+xml; charset=utf-8" />

<style type="text/css">
/*<![CDATA[*/
html,body {
height:100%;
margin:0px;
padding:0px;
}
/*//]]>*/
</style>

<script type="text/javascript">
//<![CDATA[
var i=1;
function clickCount() {
if(i>=2) {
alert("you've made "+i+" clicks");
}
i++;
}
//]]>
</script>

</head>
<body onclick="clickCount()">

<div>&#160;</div>

</body>
</html>


...the css is required for Opera. ;)

birdbrain