Home > Client Side Scripting > Check Dan Uncheck Checkbox Dengan Javascript

Check Dan Uncheck Checkbox Dengan Javascript

November 24, 2013 Leave a comment Go to comments

Berikut ini trivia untuk melakukan check dan uncheck checkbox dengan menggunakan javascript.

Javascript code :

<script language="javascript">
function checkAll(checktoggle){
var checkboxes = new Array();
checkboxes = document["input_form"].getElementsByTagName('input')
for (var i=0; i<checkboxes.length; i++)  {
if (checkboxes[i].type == 'checkbox'){
checkboxes[i].checked = checktoggle;
}
}
}
</script>

form code (html) :

<form name="input_form" action="" method="">
<input type="checkbox" value="car"> I have car </br>
<input type="checkbox" value="motor"> I have motor</br>
<input type="checkbox" value="bycle" > I have bycle </br>
<input type="button" value="Check all" onclick="checkAll(true)">
<input type="button" value="Uncheck all" onclick="checkAll(false)">
</form>

Semoga bermanfaat.🙂

  1. No comments yet.
  1. No trackbacks yet.

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s

%d bloggers like this: