+ Start a Discussion
arabisaysarabisays 

Passing text box value as query string.

I am trying to pass the  value captured from text box as query string to another visualforce page on button click.
Here is my code:

 VF Page:

<apex:page id="pg" controller="OnLoadController">
<apex:form >
<script type="text/javascript">
      function doSearch() {
        contactSearch(document.getElementById("searchBox").value);
        alert(document.getElementById("searchBox").value);

      }
</script>
<apex:actionFunction action="{!redirect}" name="contactSearch">
    <apex:param name="searchBox" value=""/>
</apex:actionFunction>
<apex:pageBlock >
        <apex:pageBlockButtons >
            <apex:commandButton value="btn1" onclick="doSearch(); return false;"/>
        </apex:pageBlockButtons>
        <input type="text" id="searchBox" />
    </apex:pageBlock>
</apex:form>
</apex:page>

Controller:
public class OnLoadController {

    public String searchName {get; set;}

    public PageReference redirect()
    {
        searchName = Apexpages.currentPage().getParameters().get('searchBox');
        PageReference searchResult= new PageReference('/apex/VF_SearchDetails?searchCriteria='+ searchName);
        searchResult.setRedirect(true);
        return searchResult;      
       
    }

}

But it is redirecting to the page with null query string value.
Please help.
Best Answer chosen by arabisays
~Onkar~Onkar
Try this.

If possible without javascript avoid it.

<apex:page id="pg" controller="OnLoadController">
<apex:form >
<apex:pageBlock >
        <apex:pageBlockButtons >
            <apex:commandButton value="btn1" action="{!redirect}"/>
        </apex:pageBlockButtons>
         <apex:inputtext id="searchBox" value="{!searchName}"/>
    </apex:pageBlock>
</apex:form>
</apex:page>
=======================================================

public class OnLoadController {

    public String searchName {get; set;}

    public PageReference redirect()
    {
       PageReference searchResult= new PageReference('/apex/VF_SearchDetails?searchCriteria='+searchName);
        searchResult.setRedirect(true);
        return searchResult;     
      
    }

}