Javascript test for a null Apex field
DougSep 12 2011 — edited Sep 18 2011Here is some javascript code for w3schools.com illustrating the valueOf boolean method.
<html>
<body>
<script type="text/javascript">
var vamount = 8
var bool = new Boolean(vamount);
document.write(bool.valueOf());
</script>
</body>
</html>
When you execute this code in the w3schools "try it" area, the result panel shows the bool.valueOf() to be "true."
I want to use javascript in an APEX page to execute a command if a field is not null. First I would assign the value of the field to a variable (in the example below "vamount"). Then I would place that variable in this line ("var bool = new Boolean(vamount)". In the w3schools site, using "document.write(bool.valueOf())" returns "true" in the results panel. So, I assume, the value of bool is true.
The question is how can I execute one command or another depending on the value of bool is true or false.
I've tried the following at the w3schools site, but it does not work:
<html>
<body>
<script type="text/javascript">
var vamount = 8
var bool = new Boolean(vamount);
if (bool.valueOf()) == true
document.write(bool.valueOf());
</script>
</body>
</html>
What can I do to make this work?