Creating JavaScript Variables
Jump to navigation
Jump to search
This page describes how to create new variables programmatically. See JavaScript Variables for an introduction and explanation of how to create them via the menus.
// Working on Phone.sav, this creates a new JavaScript variable called weight.
project.dataFiles[0].newJavaScriptVariable("q1 == 1 ? 0.5 : 1.5", false, "weight", "Weight", null);
// Working on Phone.sav, the following creates a new JavaScript Variable called weight, positioned below Q1.
var _qBelow = project.dataFiles[0].getVariableByName("q1");
project.dataFiles[0].newJavaScriptVariable("q1 == 1 ? 0.5 : 1.5", false, "weight", "Weight", _qBelow);
See also
- QScript for an explanation of how to run this code.
- QScript Examples Library for other examples.
- QScript Reference for technical information.
- JavaScript for information about the JavaScript programming language.
- Table JavaScript and Plot JavaScript for tools for using JavaScript to modify the appearance of tables and charts.
- JavaScript Variables for detail on how to create new variables in the Variables and Questions tab using JavaScript.