最新消息:Welcome to the puzzle paradise for programmers! Here, a well-designed puzzle awaits you. From code logic puzzles to algorithmic challenges, each level is closely centered on the programmer's expertise and skills. Whether you're a novice programmer or an experienced tech guru, you'll find your own challenges on this site. In the process of solving puzzles, you can not only exercise your thinking skills, but also deepen your understanding and application of programming knowledge. Come to start this puzzle journey full of wisdom and challenges, with many programmers to compete with each other and show your programming wisdom! Translated with DeepL.com (free version)

How i can i delete a selected item out of a listbox using php,javascript? - Stack Overflow

matteradmin6PV0评论

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 badges
Add a ment  | 

2 Answers 2

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>

Articles related to this article

Post a comment

comment list (0)

  1. No comments so far