I have a custom search VisualForce page. I have an inputText area for a search term, upon hitting enter I wan't to pass that value to URL parameter. Trying to do it via JavaScript.
I want URL to be apex/pageName?s=ValueEnteredInSearchBox
This is what I have right now which isn't working.
<body id="bodyPortalCaseSearch">
<apex:form id="frmPortalCaseSearch">
<apex:pageBlock id="pbPortalCaseSearch">
<div class="table">
<div class="tableRow">
<div id="searchDiv" class="tableCell">
<apex:inputText id="searchinput" style="width:85%; height:25px;margin:0; padding: 0px 6px 0px;"
title="Portal_Search_Phrase" value="{!portalSearchModel.searchTerm}" onkeypress="insertSearchParam()"
/>
<apex:commandLink id="goSearch" title="Search" style="text-decoration:none;"
rerender="asQuestions,asAnswers,asSolutions,asIdeas,asCases,asContent">Search</apex:commandLink>
<script type="text/javascript">
function insertSearchParam() {
var val = document.getElementById("{!$Component.searchinput}").value;
document.location.search = "?s=" + val;
searches();
}
document.getElementById("{!$Component.searchinput}").onkeypress = function (e) {
if (!e) e = window.event; // resolve event instance
if (e.keyCode == '13') {
insertSearchParam();
return false;
}
}
</script>