asp.net - setTimeout is not working in JavaScript -


i m using javascript function expand/collapse gridview rows. following script.

<script type="text/javascript">     function divexpandcollapse(divname) {         var div = document.getelementbyid(divname);         var img = document.getelementbyid('img' + divname);         if (div.style.display == "none") {             div.style.display = "inline";             img.src = "img1/minus.gif";         } else {             div.style.display = "none";             img.src = "img1/plus.gif";         }     } </script> 

in gridview m calling javascript this, working fine expanding immediately. want expand panel slowly. incorrect coding settimeout function. can please me...

    <asp:templatefield itemstyle-width="20px">         <itemtemplate>             <a href="javascript:settimeout(divexpandcollapse('div<%# eval("claimmasterid") %>'),1000);">                 <img id='imgdiv<%# eval("claimmasterid") %>' width="9px" border="0" src="img1/plus.gif"                     alt="" /></a>                                 </itemtemplate>         <itemstyle width="20px" verticalalign="middle"></itemstyle>     </asp:templatefield> 

it's because it's calling function, taking return value, , passing that settimeout, when you're trying call method settimeout , pass in arguments then. use this overload instead:

window.settimeout(func, [delay, param1, param2, ...]); 

in case, be:

settimeout(divexpandcollapse ,1000, 'div<%# eval("claimmasterid") %>') 

see difference? settimeout call method , pass in parameters when so.

if don't want use overload of settimeout, can enclose method call inside function:

settimeout(function() { divexpandcollapse('div<%# eval("claimmasterid") %>') }, 1000); 

however, find first 1 far easier read (and shorter type).


Comments