0% found this document useful (0 votes)
13 views1 page

Belajar Javascript 47

The document provides a tutorial on handling checkboxes in JavaScript, including how to check and uncheck them programmatically. It includes example HTML and JavaScript code snippets for detecting checkbox states and retrieving their values. The tutorial focuses on creating a simple form to order coffee with various options using checkboxes.

Uploaded by

edlistianto
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
13 views1 page

Belajar Javascript 47

The document provides a tutorial on handling checkboxes in JavaScript, including how to check and uncheck them programmatically. It includes example HTML and JavaScript code snippets for detecting checkbox states and retrieving their values. The tutorial focuses on creating a simple form to order coffee with various options using checkboxes.

Uploaded by

edlistianto
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 1

http://blog.codingwear.

com
PHP Ajax Javascript jQuery Tutorial

A. Penanganan CheckBox di javascript


Deteksi apakah checkbox sudah dicek

checkboxObject.checked=true|false

Contoh:

<html>
<head>
<script type="text/javascript">
function check(){
document.getElementById("myCheck").checked=true
}

function uncheck(){
document.getElementById("myCheck").checked=false
}
</script>
</head>
<body>
<form>
<input type="checkbox" id="myCheck" />
<input type="button" onclick="check()"
value="Check Checkbox" />
<input type="button" onclick="uncheck()"
value="Uncheck Checkbox" />
</form>
</body>
</html>

Mengambil Nilai checkbox

<html>
<head>
<script type="text/javascript">
function createOrder(){
coffee=document.forms[0].coffee
txt=""
for (i=0;i<coffee.length;++ i){
if (coffee[i].checked){
txt=txt + coffee[i].value + " "
}
}
document.getElementById("order").value="You ordered a coffee with " + txt
}
</script>
</head>

<body>
<p>How would you like your coffee?</p>
<form>
<input type="checkbox" name="coffee" value="cream">With cream<br />
<input type="checkbox" name="coffee" value="sugar">With sugar<br />

47

You might also like