1

This is a generic question

Can I add <apex:commandbutton onclick="if condition? result 1 else result 2">

I would really appreciate a simple example if this is possible.

Thanks in advance

1
  • yes you can do it
    – Ratan Paul
    May 25, 2016 at 4:54

1 Answer 1

1

Check like this for If part use below code

<apex:commandbutton onclick="if(true){
                                  alert('this is if part');
                              }else{
                                 alert('this is else part'); 
                               }">

and for else part

<apex:commandbutton onclick="if(false){
                                      alert('this is if part');
                                  }else{
                                     alert('this is else part'); 
                                   }">

Edit --

Goto w3school code editor http://www.w3schools.com/tags/tryit.asp?filename=tryhtml_button_test

and run below code

<!DOCTYPE html>
<html>
<body>

<button type="button" onclick="if(true){
                                  alert('this is if part');
                              }else{
                                 alert('this is else part'); 
                               }">Click If!</button>

<button type="button" onclick="if(false){
                                  alert('this is if part');
                              }else{
                                 alert('this is else part'); 
                               }">Click Else!</button>
</body>
</html>
0

You must log in to answer this question.

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