DONJUAN FORUM COMMUNITY ALL IN ONE BASIC

**SELAMAT DATANG DI DONJUAN COMMUNITY FORUM ALL IN ONE**

Silahkan Registrasi & Login untuk Akses penuh ,
Terima kasih atas Kunjungan-nya
DONJUAN FORUM COMMUNITY ALL IN ONE BASIC


    Contoh Java Script Check & Uncheck All

    Share

    abian zee

    Jumlah posting : 52
    Points : 137
    Reputation : 3
    Join date : 09.12.10
    Age : 26
    Lokasi : Semarang

    Contoh Java Script Check & Uncheck All

    Post  abian zee on Wed 15 Dec 2010, 19:51

    Contoh Java Script Check & Uncheck All

    < !DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
    <html xmlns="http://www.w3.org/1999/xhtml">
    <head>
    <meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
    <title>Contoh Latihan Javascript :: Check & Uncheck All</title>
    </head>

    <script type=”text/javascript”>
    function Check(){
    //Ambil semua elemen dalam id formCheck
    allCheckList = document.getElementById(“formCheck”).elements;
    //Hitung banyaknya elemen
    jumlahCheckList = allCheckList.length;
    //Jika tombolCheck bernilai “Check All”
    if(document.getElementById(“tombolCheck”).value == “Check All”){
    for(i = 0; i < jumlahCheckList; i++){
    //semua elemen ke-i checkbox nya diset true (dicentang)
    allCheckList[i].checked = true;
    }
    //Set nilai tombolCheck menjadi “Uncheck All”
    document.getElementById(“tombolCheck”).value = “Uncheck All”;
    //Jika tombolCheck tidak bernilai “Check All” (sudah dirubah menjadi Uncheck All)
    }else{
    for(i = 0; i < jumlahCheckList; i++){
    //semua elemen ke-i checkbox nya diset false (tidak dicentang)
    allCheckList[i].checked = false;
    }
    //Set nilai tombolCheck menjadi “Check All”
    document.getElementById(“tombolCheck”).value = “Check All”;
    }
    }
    </script>

    < ?php
    $hobi = $_POST['hobi'];
    if(empty($hobi)){
    ?>

    <b>Silahkan Pilih Hobi Anda :</b>
    <form id=”formCheck” method=”POST” action=”check_all.php”>
    <input type=”checkbox” name=”hobi[1]” value=”Baca Koran” />Baca Koran

    <input type=”checkbox” name=”hobi[2]” value=”Memancing” />Memancing

    <input type=”checkbox” name=”hobi[3]” value=”Bikin Susah Orang” />Bikin Susah Orang

    <input type=”checkbox” name=”hobi[4]” value=”Menulis” />Menulis

    <input type=”checkbox” name=”hobi[5]” value=”Demonstrasi” />Demonstrasi


    <input type=”button” id=”tombolCheck” value=”Check All” onClick=”Check();”/>
    <input type=”submit” value=”Submit” />
    </form>

    < ?php
    }

    if(is_array($hobi)){
    echo ‘<b>Hobi yang anda pilih :
    ’;
    foreach($hobi as $indek=>$namahobi){
    echo ‘Hobi indek ‘.$indek.’ : ‘.$namahobi.’
    ’;
    }
    echo ‘<a href=”check_all.php”>Back &raquo;</a>’;
    }
    ?>
    </script></html>

      Waktu sekarang Wed 07 Dec 2016, 00:55