Lesson 5 (Mendapatkan Nilai Select / Combo Box)

Pada simulasi ini saya akan memberikan contoh bagaimana mengambil nilai pada komponen select atau combo box. Sebelumnya anda harus sudah memahami konsep atribut class atau id yang bisa dipelajari disini dan konsep event handler yang bisa dipelajari disini.

Berikut script nya :

<!doctype html>
<html lang="en">
<head>
  <meta charset="utf-8">
  <title>Lesson 5</title>
 
  <!-- cara menggunakan jQuery, import file js -->
  <script src="lib/jquery-1.11.0.min.js"></script>
 
  <script>
	function getComboBoxValue() {
		// pengambilan nilai combo box yang memiliki id "sampleComboBox"
		var comboBoxValue = $('#sampleComboBox').val();
 
		alert('value combo box : ' + comboBoxValue);
	}
  </script>
</head>
<body>
 
	<!-- contoh combo box dengan id sampleComboBox -->
	<select id="sampleComboBox">
		<option>option 1</option>
		<option>option 2</option>
		<option>option 3</option>
	</select>
 
	<input type="button" value="Submit" onClick="getComboBoxValue()" />
 
</body>
</html>

Atau bisa dilihat simulasinya disini.

– marifnst –

Leave a Reply

Your email address will not be published. Required fields are marked *

Afiseaza emoticoanele Locco.Ro