admin管理员组文章数量:1023857
I got 2 buttons. One is to add an item to the listbox. The other is to delete something out of the listbox. The filling happens with an array. So what I need to know is: how can i delete a selected item out of the listbox?
Thanks Stijn
I got 2 buttons. One is to add an item to the listbox. The other is to delete something out of the listbox. The filling happens with an array. So what I need to know is: how can i delete a selected item out of the listbox?
Thanks Stijn
Share Improve this question asked Jan 27, 2010 at 9:53 stijnstijn 312 silver badges6 bronze badges2 Answers
Reset to default 4<script type='text/javascript'>
function removeItem(selectbox)
{
var i;
for(i=selectbox.options.length-1;i>=0;i--)
{
if(selectbox.options[i].selected)
selectbox.remove(i);
}
}
</script>
<SELECT id="item" NAME="item" MULTIPLE size=6 width=10></SELECT>
<input type=button onClick="removeItem(item)"; value='Remove Selected Item'>
You can delete one by one using this function.
<select id="list">
<option>A</option>
<option>B</option>
<option>C</option>
</select>
<button onclick="remove();">Remove</button>
<script>
function remove ()
{
var list = document.getElementById('list');
list[list.selectedIndex].remove();
}
</script>
I got 2 buttons. One is to add an item to the listbox. The other is to delete something out of the listbox. The filling happens with an array. So what I need to know is: how can i delete a selected item out of the listbox?
Thanks Stijn
I got 2 buttons. One is to add an item to the listbox. The other is to delete something out of the listbox. The filling happens with an array. So what I need to know is: how can i delete a selected item out of the listbox?
Thanks Stijn
Share Improve this question asked Jan 27, 2010 at 9:53 stijnstijn 312 silver badges6 bronze badges2 Answers
Reset to default 4<script type='text/javascript'>
function removeItem(selectbox)
{
var i;
for(i=selectbox.options.length-1;i>=0;i--)
{
if(selectbox.options[i].selected)
selectbox.remove(i);
}
}
</script>
<SELECT id="item" NAME="item" MULTIPLE size=6 width=10></SELECT>
<input type=button onClick="removeItem(item)"; value='Remove Selected Item'>
You can delete one by one using this function.
<select id="list">
<option>A</option>
<option>B</option>
<option>C</option>
</select>
<button onclick="remove();">Remove</button>
<script>
function remove ()
{
var list = document.getElementById('list');
list[list.selectedIndex].remove();
}
</script>
本文标签: How i can i delete a selected item out of a listbox using phpJavaScriptStack Overflow
版权声明:本文标题:How i can i delete a selected item out of a listbox using php,javascript? - Stack Overflow 内容由热心网友自发贡献,该文观点仅代表作者本人, 转载请联系作者并注明出处:http://it.en369.cn/questions/1745571068a2156741.html, 本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌抄袭侵权/违法违规的内容,一经查实,本站将立刻删除。
发表评论