Skip to main content

getValue()

returns the current value/state of a Checkbox control

getValue(): string | boolean;

Returns:

Either a string with the current value of the control or a boolean value with the state of the control.

Example

// returns a value if the value is specified for the checkbox
const value = form.getItem("checkbox").getValue(); // -> "checkbox_value"

// returns a state if the value is not specified for the checkbox
const state = form.getItem("checkbox").getValue(); // -> true/false
  • If the value property is not set for a control, the method returns the state of the control:
const form = new dhx.Form("form_container", {
rows: [
{
type: "checkbox",
label: "I agree",
name: "agree",
id: "agree",
checked: true
}
]
});

const state = form.getItem("checkbox").getValue(); // -> true/false
  • If the value property is defined, the method returns a string value. In addition, if the checked option is set to true, the method returns the value of a control, otherwise - returns an empty string (""):
const form = new dhx.Form("form_container", {
rows: [
{
type: "checkbox",
label: "I agree",
name: "agree",
id: "agree",
checked: false,
value: "checkbox_value"
}
]
});

const value = form.getItem("checkbox").getValue(); // -> ""