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;"
                        <script type="text/javascript">
                            function insertSearchParam() {
                                var val = document.getElementById("{!$Component.searchinput}").value;
                                document.location.search = "?s=" + val;
                            document.getElementById("{!$Component.searchinput}").onkeypress = function (e) {
                                if (!e) e = window.event; // resolve event instance
                                if (e.keyCode == '13') {
                                    return false;

1 Answer 1


Best bet is a form using GET method.

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

enter image description here

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .