1

VF Page:

<apex:form id="fm">
      <apex:actionFunction name="searchbox"  action="{!searchbox}"  rerender="pb">
       <apex:param name="x" value="" assignTo="{!IsEmailValue}" />  

    </apex:actionFunction> 


     <script>         
    function conRec () {
        //  alert('conRec');
        var pattern = /^\w+@[a-zA-Z_]+?\.[a-zA-Z]{2,3}$/;
        var SearchVal = document.getElementById('pg:fm:pb:SearchValue').value;
        var IsEmailValue;
        alert(SearchVal);
        if(SearchVal.match(pattern)){
            IsEmailValue =SearchVal;
            alert('true');
        }else{
            IsEmailValue ='';
            alert('False');
        }
        searchbox(IsEmailValue);
    }


    </script>



    <apex:slds />
    <apex:pageBlock id="pb" >


        <div class="slds-scope slds-box">
            <apex:outputPanel >                   
                <div id="formBlock">

                    <div id="showErrorMsgbuserName">
                        <div class="slds-form-element">
                            <div class="slds-align_absolute-center">
                                <!--- <apex:input value="{!searchBoxstring}"  id="SearchID" styleClass="searchBox"/>  --->

                                <apex:input value="{!searchBoxstring}" styleClass="searchBox" id="SearchValue" />
                                &nbsp;  &nbsp;  &nbsp; 
                               <!--- <apex:commandButton value="Search" onClick="conRec()" />--->
                                  <input type="button" value="Search" onClick="conRec()" class="slds-button slds-button-brand"/>
                            </div> 
                        </div>
                    </div>

                </div>

                <apex:pageMessages id="Error" escape="false" />


                <br/>
                <br/>    
                <apex:dataTable value="{!result}" var="con" border="1" cellpadding="5" cellspacing="4" bgcolor="lightblue">
                    <apex:column value="{!con.Name}" styleClass="controls">
                        <apex:facet name="header">Name</apex:facet>
                    </apex:column>
                    <apex:column value="{!con.Email}" styleClass="controls">
                        <apex:facet name="header">Email</apex:facet>
                    </apex:column>
                    <apex:column value="{!con.Phone}" styleClass="controls">
                        <apex:facet name="header">Phone</apex:facet>
                    </apex:column>
                </apex:dataTable>                   

            </apex:outputPanel>   
        </div>
    </apex:pageBlock>    


</apex:form>

Controller:

public class SearchPageController {

public string searchboxstring{get; set;}
public string IsEmailValue {get; set;}

public String Email{get;set;}

public list<contact> result {get; set;}

public SearchPageController()
{
    result = new list<Contact>();
}

public void  searchbox(){

    system.debug('IsEmailValue-->' + IsEmailValue);         

}   
}

I was trying to Print IsEmailValue value but it's empty. Please help us on this.

  • Are you getting the value in JS? – rahul gawale Sep 10 at 15:07

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Browse other questions tagged or ask your own question.