hello again,
Im tring to stop this redirect with a button. this is the orginal script.

<script language="JavaScript" type="text/javascript">  
    var count =16  
    var redirect="example.php"  

    function countDown(){  
     if (count <=0){  
      window.location = redirect;  
     }else{  
      count--;  
      document.getElementById("timer").innerHTML = ""+count+" seconds."  
      setTimeout("countDown()", 3000)  
     }  
    }  
        </script>  

    Browser refresh in     
    <span id="timer">  
    <script>  
     countDown(); 
    </script>  
    </span>  

and this is what i have been tring that doesnt work

<html>
<body>

<p id="count"></p>
<button onclick="myStopFunction()">Stop</button>   

<script language="JavaScript" type="text/javascript">  
    var count =16  
    var redirect="example.php"  

    function countDown(){  
     if (count <=0){  
      window.location = redirect;  
     }else{  
      count--;  
      document.getElementById("timer").innerHTML = ""+count+" seconds."  
      setTimeout("countDown()", 3000)  
     }  
    }  
function myStopFunction()
{
clearTimeout(count);
}
    </script>  

    Browser refresh in     
    <span id="timer">  
    <script>  
     countDown(); 
    </script>  
    </span>  
 </body>
</html>

any help with this would be great
Thank you

You can use clearTimeout if you store the result of setTimeout in a variable, and pass that as parameter.

Your code is missing several semi-colons...

thanks pritaeas went a differant way, works perfect.
thanks again

<HTML>
<HEAD>
    <SCRIPT LANGUAGE="JavaScript">

    var time_left = 20;
    var cinterval;
    var timestatus=1;
    var redirect="example.php";

    function time_dec(){
        time_left--;
        document.getElementById('countdown').innerHTML = time_left;
        if(time_left <=0){
                window.location = redirect;
    }
    }

    function resumetime()
    {
        //time_left = 20;
        clearInterval(cinterval);
        cinterval = setInterval('time_dec()', 1000);
    }

    function defaultstart()
    {
        time_left = 20;
        clearInterval(cinterval);
        cinterval = setInterval('time_dec()', 1000);
    }

    function stopstarttime()
    {
        if(timestatus==1)
    {
        clearInterval(cinterval);
        document.getElementById('stopbutton').value="Start";
        timestatus=0;
    }
        else
    {
        clearInterval(cinterval);
        cinterval = setInterval('time_dec()', 1000);
        document.getElementById('stopbutton').value="Stop";
        timestatus=1;
    }

    }

    defaultstart();

    </SCRIPT>
</HEAD>
</HEAD>

<body>
    Redirecting In <span id="countdown">20</span>.
    <INPUT TYPE="button" value="stop" id="stopbutton" onclick="stopstarttime()">
</body>
</HTML>
Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.