function readOnly(count){ }
Starting November 20, the site will be set to read-only. On December 4, 2023,
forum discussions will move to the Trailblazer Community.
+ Start a Discussion
afoxmicroedgeafoxmicroedge 

Pass value of inputText field to URL parameter

I am building a custom search VF page. I have an inputText area where user enters search term. When they hit enter I wan't to pass that value to URL so it looks like /apex/PageName?s=ValueEntered

 

This is what I have so far which isn't working. Any guidance?

 

  <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>

 

Big VBig V

Whenever you use $Component it should be succeeded  by parent coponent id(if any) .


In your case:

 

document.getElementById("{!$Component.frmPortalCaseSearch.pbPortalCaseSearch.searchinput}").onkeypress = function(e){
    if (!e) e = window.event;   // resolve event instance
    if (e.keyCode == '13'){
      insertSearchParam();
      return false;
    }
  }
afoxmicroedgeafoxmicroedge

 

Correct me if I am wrong but isn't that not true based on the above?

 

Either way, it isn't the fix for my problem. 

 

edit: sorry the screenshot is crude, here is the link: Best Practices for Accessing Component IDs