Skip to content

Instantly share code, notes, and snippets.

@TzuYangLin
Last active August 29, 2015 14:07
Show Gist options
  • Save TzuYangLin/d6ac206b436e0894ccc7 to your computer and use it in GitHub Desktop.
Save TzuYangLin/d6ac206b436e0894ccc7 to your computer and use it in GitHub Desktop.
Example: How to delete the option of select
<html>
<head>
<meta http-equiv=Content-Type content="text/html; charset=utf-8">
<script language="JavaScript">
function test()
{
var select = document.getElementById("test");
for(i=select.options.length-1;i>=0;i--)
{
select.remove(i);
}
}
</script>
</head>
<body>
<select id="test">
<option value=0>0</option>
<option value=1>1</option>
<option value=2>2</option>
<option value=3>3</option>
<option value=4>4</option>
<option value=5>5</option>
</select>
<input type=button value="test" onClick="test();">
</body>
</html>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment