Javascript : Objek

Selasa, 26 Februari 2019

Javascript : Objek


Objek










Script Objek Array:






<HTML>
<HEAD>
<TITLE>Properti prototype</TITLE>
</HEAD>
<BODY>
<SCRIPT LANGUAGE = "JavaScript">
<!--
   function tampilkanElemenArray() {
      for (var i = 0; i < this.length; i++) {
         document.write("[" + i + "] = " +
                        this[i] + "<BR>");
      }
   }   
   Array.prototype.cetak = tampilkanElemenArray;
   var musik = new Array("Jazz", "Rock",
                         "keroncong", "Dangdut");
   var tanaman = new Array("Aglaonema", "Begonia",
                           "Bromelia");
   document.write("Isi array musik: <BR>");
   musik.cetak();
   document.write("Isi array tanaman: <BR>");
   tanaman.cetak();
//-->
</SCRIPT>
</BODY>
</HTML>



Hasil :



Script Objek Radio :



<HTML>
<HEAD>
<TITLE>Mengakses Objek radio</TITLE>
</HEAD>
<BODY>
Klik pada musik yang paling Anda sukai<BR>
<FORM NAME = "formTes"
      METHOD  = "GET">
<INPUT TYPE = "RADIO"
       NAME = "radioMusik"
       VALUE = "Jazz"
       onClick = "info()">Jazz<BR>
<INPUT TYPE = "RADIO"
       NAME = "radioMusik"
       VALUE = "Keroncong"
       onClick = "info()">Keroncong<BR>
<INPUT TYPE = "RADIO"
       NAME = "radioMusik"
       VALUE = "Dangdut"
       onClick = "info()">Dangdut<BR>
<INPUT TYPE = "RADIO"
       NAME = "radioMusik"
       VALUE = "Lainnya"
       onClick = "info()">Lainnya<BR>
<HR>
Info:
<INPUT TYPE = "TEXT"
       NAME = "fieldMusik"
       SIZE = "40">
</FORM>
<SCRIPT LANGUAGE = "JavaScript">
<!--
   function info() {
      for (var i = 0; i < 4; i++)
         if (document.formTes.radioMusik[i].checked)
            document.formTes.fieldMusik.value =
               document.formTes.radioMusik[i].value;
   }
//-->
</SCRIPT>
</BODY>
</HTML>

Hasil :



Script Objek Password :


<HTML>
<HEAD>
<TITLE>Mengakses Objek password</TITLE>
</HEAD>
<BODY>
<FORM NAME = "formTes"
      ACTION = "tesform.htm"
      METHOD  = "POST">
<PRE>
Password Pengganti  : <INPUT TYPE = "PASSWORD"
       NAME = "password_1">
Password Sekali Lagi: <INPUT TYPE = "PASSWORD"
       NAME = "password_2">
</PRE>
<INPUT TYPE = "BUTTON"
       NAME = "tombolProses"
       VALUE = "Proses"
       onClick = "cekPassword()">
</FORM>
<SCRIPT LANGUAGE = "JavaScript">
<!--
   function cekPassword() {
      if (document.formTes.password_1.value !=
          document.formTes.password_2.value)
         alert("Dua password yang Anda masukkan tidak sama");
      else
         window.location.href = "tesform.htm";
   }
//-->
</SCRIPT>
</BODY>
</HTML>


Hasil :


0 komentar :

Posting Komentar