Member Avatar for ficus

Hi Guys hope you can help me

I am using the following AJAX code to get SUB-Buttons.

If no new button is selected I need the main button to revert back to the originally selected main button on mouseout with a timeout function or delay please help.

so the code below works but i need a delay or timout

http://entertainment.iafrica.com/
the above link is what its how its suppost to function.

<script language="JavaScript"> function getXMLHTTP() { //fuction to return the xml http object var xmlhttp=false; try{ xmlhttp=new XMLHttpRequest(); } catch(e) { try{ xmlhttp= new ActiveXObject("Microsoft.XMLHTTP"); } catch(e){ try{ req = new ActiveXObject("Msxml2.XMLHTTP"); } catch(e1){ xmlhttp=false; } } } return xmlhttp; } function getCity(strURL) { var req = getXMLHTTP(); if (req) { req.onreadystatechange = function() { if (req.readyState == 4) { // only if "OK" if (req.status == 200) { document.getElementById('citydiv').innerHTML=req.responseText; } else { alert("There was a problem while using XMLHTTP:\n" + req.statusText); } } } req.open("GET", strURL, true); req.send(null); } } </script> <td background="images/button_main.gif" class="hand" onMouseOver="getCity('getButtons.php?city=<?php echo $city;?>');" onMouseOut="getCity('getButtons.php?city=<?php echo $original_city;?>');" onClick="">BUTTON</span></td>
Member Avatar for R0bb0b

adjusted the onmouseout function

<td background="images/button_main.gif" class="hand" onMouseOver="getCity('getButtons.php?city=<?php echo $city;?>');" onMouseOut="setTimeout('getCity(\'getButtons.php?city=<?php echo $original_city;?>\')', 3000);" onClick="">BUTTON</span></td>
Member Avatar for ficus

Thank you very much, the above was just what i needed. I was close but it was the backslashes that had me confused.

I would also really appreciate it if you could help me with a "clearTimeout" on the "onMouseOver" button so that the sub-menu doesn't jump back to the original menu while you are busy mousing over other buttons?

<td background="images/button_main.gif" class="hand" onMouseOver="getCity('getButtons.php?city=<?php echo $city;?>');clearTimeout();" onMouseOut="setTimeout('getCity(\'getButtons.php?city=<?php echo $original_city;?>\')', 3000);" onClick="">BUTTON</span></td>
Member Avatar for ficus

Thank you for all the help i finally worked it out.

var timeOut; <td background="images/button_main.gif" class="hand" onMouseOver="getCity('getButtons.php?city=<?php echo $city;?>');clearTimeout(timeOut);" onMouseOut="timeOut=setTimeout('getCity(\'getButtons.php?city=<?php echo $original_city;?>\')', 3000);" onClick="">BUTTON</span></td>
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.