Jump to content

help with clearTimeout


irkevin

Recommended Posts

Hi,

 

what i have is a block of javascript code to refresh contents in an Iframe. So far it works,

 

Now, on the page containing the iframe, i have a form, what i want is, when i move my mouse over the form, the refresh function should stop.

 

here is the html

 

<iframe name="shout" id="shout" src="chat.php" style="overflow:auto;overflow-x: hidden;" frameborder="0" scrolling="yes" marginheight="0" marginwidth="0" height="150" width="100%"></iframe><br /><br />

<form method="post" name="posting" id="posting">
<table width="100%" border="0" cellspacing="0" cellpadding="5">
  <tr>
	<td colspan="6">Your Message:</td>
  </tr>
  <tr>
	<td colspan="6"><input type="text" name="post" id="post" style="width:300px;" />

<input type="submit" value="Submit Shout" name="submit" /></td>
  </tr>
</table>

 

The JS code:

 

<script type="text/javascript">

var milliSecondsToWait = 1000;

function reloadIFrame(){
document.frames['shout'].location.href =
"chat.php?" + (new Date().getTime());
myVar = setTimeout("reloadIFrame()",milliSecondsToWait);
}
var myVar = setTimeout("reloadIFrame()",milliSecondsToWait);

</script>

 

Thats it, how do i clear the timeout when i move my mouse over the <input type="text" .. Help plz

Link to comment
https://forums.phpfreaks.com/topic/142983-help-with-cleartimeout/
Share on other sites

hum...weird...works in a function though:

 

<input type="text" name="post" id="post" style="width:300px;" onmouseover="stopReload()" />

 

<script type="text/javascript">

var milliSecondsToWait = 1000;

function reloadIFrame(){
document.frames['shout'].location.href =
"chat.php?" + (new Date().getTime());
myVar = setTimeout("reloadIFrame()",milliSecondsToWait);
}
function stopReload ( ) {
  clearTimeout(myVar);
}
var myVar = setTimeout("reloadIFrame()",milliSecondsToWait);

</script>

did this work for you?

 

Because here when i use this code, when i move my mouseover the textbox, the page still refresh, even when i type in .. i wonder why it wont accept to function stopReload :S

 

i made a test like this:

 

function stopReload ( ) {

alert("I work");

}

 

when i put my mouse over the textbox, i get a message with 'i work'.. Which mean the function works but it looks like the clearTimeout isn't working.. Any ideas?

this worked for me:

<iframe name="shout" id="shout" src="chat.php" style="overflow:auto;overflow-x: hidden;" frameborder="0" scrolling="yes" marginheight="0" marginwidth="0" height="150" width="100%"></iframe><br /><br />

<form method="post" name="posting" id="posting">
<table width="100%" border="0" cellspacing="0" cellpadding="5">
     <tr>
      <td colspan="6">Your Message:</td>
     </tr>
     <tr>
      <td colspan="6"><input type="text" name="post" id="post" style="width:300px;" onmouseover="stopReload()" />
      
<input type="submit" value="Submit Shout" name="submit" /></td>
     </tr>
</table>
<script type="text/javascript">

var milliSecondsToWait = 1000;

function reloadIFrame(){
document.getElementById('shout').src =
"chat.php?" + (new Date().getTime());
myVar = setTimeout("reloadIFrame()",milliSecondsToWait);
}
function stopReload ( ) {
  clearTimeout(myVar);
}
var myVar = setTimeout("reloadIFrame()",milliSecondsToWait);

</script>

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.