JavaScript: Calling xajax functions with boolean parameter

When passing a boolean value from javascript to a xajax function, the value is converted to string in the xajax function.

You need to compare the string value of the boolean value (from JavaScript) in xajax function.

eg, the following code in xajax function will not work:

function my_xajax_function($flag) {
  $obj = new xajaxResponse();
  $obj->assign('some_id_name', 'className', $flag? 'true_class' : 'false_class');
  return $obj;
}

In the above code, the ‘false_class’ will always be assigned.

Replace line 3 from above with the following:

$obj->assign(’some_id_name’, ‘className’, ($flag == “true") ? ‘true_class’ : ‘false_class’);

Leave a Reply

Your email address will not be published. Required fields are marked *