Robotics - Using Javascript - send Enter key to text box
I am creating an automation in a web database with a search box that does not have a search button. The only way to trigger the search function is to hit enter in the text box. I am using the following javascript which compiles but does not achieve the enter press. Any ideas or suggestions would be greatly appreciated:
function os_RaiseEvent(eventname)
{
var element = document.querySelector('[id$="_text"]');
var event;
if(document.createEvent)
{
event = document.createEvent("HTMLEvents");
event.initEvent(eventname, true, false);
if(eventname == "keydown" || eventname == "keyup")
{
event.keyCode = 13;
}
element.dispatchEvent(event);
}
else if(document.createEventObject)
{
event = document.createEventObject();
if(eventname == "keydown" || eventname == "keyup")
{
event.keyCode = 13;
}
element.fireEvent("on" + eventname, event);
}
return true;
}