I am getting the value of booleanvariable in controller as below. I want to display an alert on visual force page when boolean variable is true.I see the value of Booleanvariable is true in the url,but alert is not triggering.
public with sharing class TestBoolean {
boolean pbv;
public TestBoolean(){
try{ pbv = boolean.valueOf(system.CurrentPageReference().GetParameters().get('BooleanVariableName'));
}catch(Exception e){
pbv = false;
}
}
If I just run alert without If condition and no parameter, its displaying alert.
Any help is appreciated.
Java script for alert on visual force page
window.onload = showAlert(!pbv);
function showAlert(!pbv)
{
if(!pbv) {
alert('Hi I am the alert you have been waiting for');
}
}
Best Answer
All you need to do is this for the JS (Global merge variables)
Additionally (Not needed for above) if you want to use the PBV on the page you need to assign getters and setters
then use merge fields on the page:
Also, you should use the first example in my answer to your previous question. The try catch in not applicable in your case