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
ForceLoverForceLover 

Hide a button upto click another button

Hi Everyone,

 

I have two buttons checkformat,search.I want to disable my search button untill user check for his format with checkformat button.I'm using a javascript to check the format of my inputtext.

 

Here is my code,

 

<apex:panelGroup >
          <apex:inputText id="searchText" value="{!searchText}" onblur="checkingstring(this)"/>
          <button onclick="alert('Correct Format !');">CheckFormat</button>         
          <apex:commandButton value="Search" action="{!search}" rerender="resultsBlock" status="status" disabled="true"/></apex:panelGroup>

 

<script>
function checkingstring(searchText){
    var regexp = /^[A-Z]{2}\d{4}-\d{5}$/i; //AANNNN-NNNNN A = Capital N = Number
    if (!regexp.exec(searchText.value)) {
        alert("The syntax is always as follows: AANNNN-NNNNN (A= Alpha/Letter; N= Number) i.e.FL0301-12345</b>");  
    }
}
</script>

 

 

for my search button it will search for the text on the object if it is not on object it will create a record with the searchtext and it will display thwe record in edit mode to update some of the values..if the record exists it will simply displays the record..

 

public pagereference search(){

 

/// code goes here

 

}

 

Search should be enable only when the text is in correct format....

 

 

ryanjuptonryanjupton

I solved your problem using jQuery.


At the top of you page add

<script src="http://code.jquery.com/jquery-1.9.1.min.js"></script>
<script src="http://code.jquery.com/jquery-1.9.1.min.js"></script>

 Then I changed you function to

 

    <script type="text/javascript">
        var $j = jQuery.noConflict();
        function checkingstring(searchText){
        var regexp = /^[A-Z]{2}\d{4}-\d{5}$/i; //AANNNN-NNNNN A = Capital N = Number
        if (!regexp.exec(searchText.value)) {
          alert("The syntax is always as follows: AANNNN-NNNNN (A= Alpha/Letter; N= Number) i.e.FL0301-12345</b>");  
    }else{
    	$j("[id$='searchBtn']").attr("class","btn");
        alert("Button should be enabled");
    }
}
</script>

 Then modify your Apex a bit

<apex:panelGroup >
          <apex:inputText id="searchText" value="{!searchText}" onblur="checkingstring(this)"/>
          <button onclick="alert('Correct Format !');">CheckFormat</button>         
          <apex:commandButton id="searchBtn" value="Search" action="{!search}" rerender="resultsBlock" status="status" disabled="true"/></apex:panelGroup>

 The addition there was the id on <apex:commandButton>

 

That gives you what you're looking for.

ForceLoverForceLover

Hi ryan,

 

Thanks for your help.It's not working in my case the search button is always disable and the checkformat always giving the correct format alert only, for worng format text also.

 

    	$j("[id$='searchBtn']").attr("class","btn");

 Need to change the class, btn in above line