javascript membaca tag select element html

selected javascript onchange onclick option value text html


<html>
<head>
<script type="text/javascript">
function getElements() {
//alert('oi');
var e = document.getElementById("provinsi");
var v = e.options[e.selectedIndex].value;
var t = e.options[e.selectedIndex].text;
alert(v+' '+t);
 }
</script>
</head>
<body>
<input type="button" onclick="getElements()" value="select value" /><br />
<select class='l' id='provinsi' onChange="getElements()">
<option value='0'>Select Province</option>
<option value='s1'>Nanggroe Aceh Darusalam</option>
<option value='s2'>Sumatera Utara</option>
<option value='s3'>Riau</option>
<option value='s32'>Papua Barat</option>
<option value='s33'>Papua</option>
</select>
</body>
</html>

Published by

G3n1k

just to remember what i had known :)

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