You need to sign in to do that
Don't have an account?
afoxmicroedge
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>
Whenever you use $Component it should be succeeded by parent coponent id(if any) .
In your case:
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