Properti checked Input Checkbox
Definisi dan penggunaan
checked
Atur atau kembalikan status terpilih kotak centang.
Properti ini merefleksikan properti checked HTML.
Lihat pula:
Panduan HTML:Atribut checked <input> HTML
Contoh
Contoh 1
Atur status terpilih kotak centang:
function check() { document.getElementById("myCheck").checked = true; } function uncheck() { document.getElementById("myCheck").checked = false; }
Contoh 2
Lihat apakah kotak centang terpilih:
var x = document.getElementById("myCheck").checked;
Contoh 3
Gunakan kotak centang untuk mengubah teks input menjadi huruf besar:
document.getElementById("fname").value = document.getElementById("fname").value.toUpperCase();
Contoh 4
Beberapa kotak centang di formulir:
var coffee = document.forms[0]; var txt = ""; var i; for (i = 0; i < coffee.length; i++) { if (coffee[i].checked) { txt = txt + coffee[i].value + " "; } } document.getElementById("order").value = "Kopi yang anda pilih ditambahkan dengan: " + txt;
Sintaks
Kembalikan properti checked:
checkboxObject.checked
Atur properti checked:
checkboxObject.checked = benar|salah
Nilai atribut
Nilai | Deskripsi |
---|---|
true|false |
Menentukan apakah kotak centang seharusnya dipilih
|
Detil Teknik
Nilai kembalian: | Bilangan Boolean, kembali jika kotak centang dipilih true kembali jika kotak centang tidak dipilih false . |
---|
Dukungan Peramban
Chrome | Edge | Firefox | Safari | Opera |
---|---|---|---|---|
Chrome | Edge | Firefox | Safari | Opera |
Dukungan | Dukungan | Dukungan | Dukungan | Dukungan |