The question is practically in the title. I am trying to simulate an enter button click on the find a file input (with id "inplaceSearchDiv_WPQ1_lsinput") of SharePoint, after having populated it with a value that I get from the query string. (See code snippet below which I added as a script in the AllItems.aspx view page)
$( window ).on( "load", function() {
var e = jQuery.Event("keypress");
e.which = 13; //choose the one you want
e.keyCode = 13;
var input = document.getElementById("inplaceSearchDiv_WPQ1_lsinput");
var textval = getParameterByName("Name");
input.value = textval;
//document.getElementById("inplaceSearchDiv_WPQ1_lsimg").click();
$("#inplaceSearchDiv_WPQ1_lsinput").trigger(e);
})
I also tried the .click() function on the input itself, on the span and search image.
Both the .trigger with the 'e' event and the .click() methods do nothing: practically the code is passed and no click is fired.
The console returns the below errors intermittently:
HTTP 403 - The server understood the request, but is refusing to fulfill it.
POST - https://outlook.office365.com/owa/
And:
HTTP 401 - DENIED - The requested resource requires user authentication.
These errors appear regardless of the code being included or not. I am mentioning them as I am wondering whether they could be preventing the methods from working.
Does SharePoint block such events? If yes how can I go around it?!
Any ideas?
Update: I noticed that even though the value is being filled in by javascript, I cannot manually submit the input, unless I manually type in the text, remove the javascript work and click enter or click the search button. This may be the reason why I cannot submit it programatically either. Nonetheless, I still would like someone's input about my problem. Perhaps another way of achieving the same thing. Thanks!