www.webdeveloper.com
Results 1 to 6 of 6

Thread: [RESOLVED] Counter problem revisted

Hybrid View

  1. #1
    Join Date
    Nov 2009
    Posts
    65

    resolved [RESOLVED] Counter problem revisted

    Hey,

    This code works in FF3.6 but doesn't in IE8. It gives this error: Object doesn't support this action on line 43.
    HTML Code:
    <input type="button" class="row" value="starten" onclick="start()" />
    Code:
    var timer = "";
    function start(){
    	temp = document.getElementById("timer").value;
    	temp = parseFloat(temp); // Waarde uit een html element uitlezen levert telkens een stringvalue op, om te incrementeren heb je de omzetting naar een getalformaat nodig
    	temp++;
    	document.getElementById("timer").value = temp;
    	timer = window.setTimeout("start()", 30); // timer = window.setTimeout
    }
    
    function stop(){
    	window.clearTimeout(timer);
    	var resultaat = document.getElementById("timer").value;
    	if(resultaat == 100){
    		alert("Proficiat! Perfecte timing!");
    		}
    		else if((resultaat == 99) || (resultaat == 101)){
    			alert("Bijna perfect, maar nog niet helemaal");
    			}
    			else{
    				alert("Nog een beetje oefenen, je timing kan beter");
    				}
    }

    Full html
    HTML Code:
    <!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">
    <head>
    <title>Timing</title>
    <meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
    <link rel="stylesheet" type="text/css" href="timing.css" />
    <script type="text/javascript">
    /* <![CDATA[ */
    var timer = "";
    function start(){
    	temp = document.getElementById("timer").value;
    	temp = parseFloat(temp); // Waarde uit een html element uitlezen levert telkens een stringvalue op, om te incrementeren heb je de omzetting naar een getalformaat nodig
    	temp++;
    	document.getElementById("timer").value = temp;
    	timer = window.setTimeout("start()", 30); // timer = window.setTimeout
    }
    
    function stop(){
    	window.clearTimeout(timer);
    	var resultaat = document.getElementById("timer").value;
    	if(resultaat == 100){
    		alert("Proficiat! Perfecte timing!");
    		}
    		else if((resultaat == 99) || (resultaat == 101)){
    			alert("Bijna perfect, maar nog niet helemaal");
    			}
    			else{
    				alert("Nog een beetje oefenen, je timing kan beter");
    				}
    }
    /* ]]> */
    </script>
    </head>
    <body>
    <div id="wrapper">
    <form action="">
    <fieldset>
    	<legend>Timing</legend>
    	<p>Probeer de timer te stoppen op <span>100</span></p>
    	<input type="text" id="timer" value="0" onselect="blur()" />
    	<div id="buttons">
    		<input type="button" class="row" value="starten" onclick="start()" />
    		<input type="button" class="row" value="stoppen" onclick="stop()" />
    		<input type="reset" class="row" value="opnieuw" />
    	</div>
    </fieldset>
    </form>
    </div>
    </body>
    </html>
    Any idea why this doesn't work in IE8?

  2. #2
    Join Date
    Feb 2010
    Location
    Amsterdam
    Posts
    174
    weird looks good to me, i changed some things but dont have ie8 installed

    Code:
    <!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">
    <head>
    <title>Timing</title>
    <meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
    <link rel="stylesheet" type="text/css" href="timing.css" />
    <script type="text/javascript">
    /* <![CDATA[ */
    var timer = "";
    function start(){
    	temp = document.getElementById("timer").value;
    	temp = parseInt(temp); // Waarde uit een html element uitlezen levert telkens een stringvalue op, om te incrementeren heb je de omzetting naar een getalformaat nodig
            // parseInt ipv parseFloat omdat je een integer inleest ipv een decimaal
    	temp++;
    	document.getElementById("timer").value = temp;
    	timer = window.setTimeout(start, 30); // timer = window.setTimeout 
            // quotes om start verwijderd omdat je een functie aanroept
    }
    
    function stop(){
    	window.clearTimeout(timer);
    	var resultaat = document.getElementById("timer").value;
    	if(resultaat == 100){
    	 alert("Proficiat! Perfecte timing!");
    	}
    	else if(resultaat == 99 || resultaat == 101){
    		alert("Bijna perfect, maar nog niet helemaal");
    	}
    	else{
    		alert("Nog een beetje oefenen, je timing kan beter");
    	}
            
    } // einde function stop(){
    /* ]]> */
    </script>
    </head>
    <body>
    <div id="wrapper">
    <form action="">
    <fieldset>
    	<legend>Timing</legend>
    	<p>Probeer de timer te stoppen op <span>100</span></p>
    	<input type="text" id="timer" value="0" onselect="this.blur()" />
    	<div id="buttons">
    		<input type="button" class="row" value="starten" onclick="start()" />
    		<input type="button" class="row" value="stoppen" onclick="stop()" />
    		<input type="reset" class="row" value="opnieuw" />
    	</div>
    </fieldset>
    </form>
    </div>
    </body>
    </html>
    actually i only removed the quotes in the settimeout and inside if(resultaat == 99 || resultaat == 101){

    but i commented on this inside the code.

  3. #3
    Join Date
    Nov 2009
    Posts
    65
    Hm i took over the changes but I still get the error. Maybe something inside start() isn't supported by IE8?

  4. #4
    Join Date
    Feb 2010
    Location
    Amsterdam
    Posts
    174
    maybe start is a reserved word inside IE8 (seems unlikelly) you can try changing function start & function stop to function startTimer & function stopTimer

    i just tried this in IE6 and with function start & stop it did not work but it did when you rename the functions to startTimer & stopTimer!

  5. #5
    Join Date
    Dec 2009
    Location
    Colorado
    Posts
    104
    Rename your start() function and everything that references it. Call it startTimer() and stopTimer(). You are running into a naming conflict.

  6. #6
    Join Date
    Nov 2009
    Posts
    65
    maybe start is a reserved word inside IE8 (seems unlikelly) you can try changing function start & function stop to function startTimer & function stopTimer

    i just tried this in IE6 and with function start & stop it did not work but it did when you rename the functions to startTimer & stopTimer!
    Rename your start() function and everything that references it. Call it startTimer() and stopTimer(). You are running into a naming conflict.
    You found it! It works

    thanks!

Thread Information

Users Browsing this Thread

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

Tags for this Thread

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