0

Folks,

I have a button calling a function in JQuery and it has onComplete attribute. I want to check if the condition has been met or not , if not onComplete will not fire.

Here the condition I want to check is the value select in apex:selectList is an empty string. If it is empty, the onComplete will not fire.

Thank you so much.

JQuery

<script>
    function displayMessage(){
       if ($('select[id$="dropdownList"]').val() == '') {
           $('#warning').show(); 
       } else {
           $('#waiting').show();
           $('#button').hide();
           return true;  
       }
    }
</script>

Visualforce Code

<apex:commandbutton value="CONVERT"
                    onclick="displayMessage();"
                    action="{!updateDetail}"
                    oncomplete="CONVERT()"
                    rerender="button"/>

1 Answer 1

1

You need to prevent the default action, as in:

function displayMessage(event) {
  if(...) {
    event.preventDefault(); // prevents submission of the form
  } else {
    ...
  }
}
1
  • Hi @sfdcfox, thank you so much for the solution! It works in this case.
    – Pam
    Nov 25, 2022 at 18:23

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .