Hi,
I am trying to use javascript to allow the user to press enter on a search input field and have the page redirect to the search result page. So after the user enters a text, instead of having to click "Search" with the mouse, the user will press enter and the whole page will redirect to the result page. However, I am getting a weird error. After I click enter, the page merely refreshes and does not redirect ot the new page. BUT if I put a window.alert("this is a text") in teh function that redirects, it alerts then redirects fine. I can't figure out why its doing that. Here is the javascript code that does the redirect and below that the onkeydown code for the input field. Any help is greatly appreciated.
<script language="javascript">
var servername = location.host;
function SearchcBase()
{
if(document.all.item("txtcBaseSearch").value != "")
{
Redirect_oIFrame(" + servername + "/Document%20Library/SearchResult.aspx?keyword="+document.all.item("txtcBaseSearch").value);
}
}
function Redirect_oIFrame(url)
{
window.location.href = url;
}
function DetectKeyEvent(button)
{
if(window.event.keyCode == 13)
{
SearchcBase();
}
}
</script>
<INPUT class="cBaseTextBox" id="txtcBaseSearch" type="text" onKeyDown="DetectKeyEvent('hrefSearchcBase')">
I am trying to use javascript to allow the user to press enter on a search input field and have the page redirect to the search result page. So after the user enters a text, instead of having to click "Search" with the mouse, the user will press enter and the whole page will redirect to the result page. However, I am getting a weird error. After I click enter, the page merely refreshes and does not redirect ot the new page. BUT if I put a window.alert("this is a text") in teh function that redirects, it alerts then redirects fine. I can't figure out why its doing that. Here is the javascript code that does the redirect and below that the onkeydown code for the input field. Any help is greatly appreciated.
<script language="javascript">
var servername = location.host;
function SearchcBase()
{
if(document.all.item("txtcBaseSearch").value != "")
{
Redirect_oIFrame(" + servername + "/Document%20Library/SearchResult.aspx?keyword="+document.all.item("txtcBaseSearch").value);
}
}
function Redirect_oIFrame(url)
{
window.location.href = url;
}
function DetectKeyEvent(button)
{
if(window.event.keyCode == 13)
{
SearchcBase();
}
}
</script>
<INPUT class="cBaseTextBox" id="txtcBaseSearch" type="text" onKeyDown="DetectKeyEvent('hrefSearchcBase')">