How to simulate a click to make the current input lose its focus with JavaScript -


i have input @ points happens have focus. if user click in "background" of page, input loses focus. trying simulate click on background following code, doesn't work (you notice input still has focus). suggestion on how write code simulates click on "background" of page?

<!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" xml:lang="en" lang="en">     <head>         <meta http-equiv="content-type" content="text/html; charset=utf-8"/>         <script type="text/javascript" src="http://yui.yahooapis.com/2.6.0/build/yahoo/yahoo-min.js" ></script>         <script type="text/javascript" src="http://yui.yahooapis.com/2.6.0/build/event/event-min.js" ></script>         <script type="text/javascript">             yahoo.util.event.ondomready(function() {                 document.getelementbyid("input").focus();                     document.getelementbyid("main").focus();                 });         </script>     </head>     <body>         <div id="main">             <form action="/">                 <p>                     <input type="text" id="input"/>                 </p>             </form>         </div>     </body> </html> 

i imagine using blur() trick:

<script type="text/javascript">     yahoo.util.event.ondomready(function() {         document.getelementbyid("input").focus();             document.getelementbyid("input").blur();         }); </script> 

Comments

Popular posts from this blog

windows - Why does Vista not allow creation of shortcuts to "Programs" on a NonAdmin account? Not supposed to install apps from NonAdmin account? -

c++ - How do I get a multi line tooltip in MFC -

unit testing - How to mock PreferenceManager in Android? -