Take the 2-minute tour ×
Salesforce Stack Exchange is a question and answer site for Salesforce administrators, implementation experts, developers and anybody in-between. It's 100% free, no registration required.

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>
share|improve this question
add comment

1 Answer

Best bet is a form using GET method.

<apex:page>
  <form method="GET">
    <input name="s" value="ValueEnteredInSearchBox" type="text" />
    <input type="submit" />
  </form>
</apex:page>

enter image description here

share|improve this answer
add comment

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.