Quantcast
Channel: SharePoint 2010 - General Discussions and Questions forum
Viewing all articles
Browse latest Browse all 17574

Javascript function only works in edit mode

$
0
0

After an upgrade to 2020 my client found that the advanced search web part doesn't accept Enter as the default button.  It must be explicitly clicked to search.  Click Enter takes a user to the home page.  Anyway, here's my problem:

As a work around I'm subscribing to the page's keydown event and just calling the button's click method.  The problem is, my javascript, added using a Content Query Web Part, only works in Edit Mode.  Any thoughts on why?

Thank You

<script
type="text/javascript">  // call the function that registers the event
_spBodyOnLoadFunctionNames.push("initializeAll");

function initializeAll()
{
   // register the keydown event
   document.onkeydown=simulateClick;
}
function simulateClick(event)
{    
// only for the enter key
   if (event.keyCode == 13)   
   {
 document.getElementById("ctl00_m_g_ea6e689d_a19d_42b1_8041_559641276719_ASB_BS_SRCH_1").click();   
   }
}</script>



Nate


Viewing all articles
Browse latest Browse all 17574

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>