/    Sign up×
Community /Pin to ProfileBookmark

Removed items in asp:listbox re-appear after refresh

Hi,

This seems really stupid i cant get my head around this.

I have a listbox that has items added to it from selections from another one. I have also added code that an item can be double clicked to remove it, which works, until the page is refreshed and the items all com back.

my code is

[CODE]
function DeleteItem()
{ var list = document.getElementById(“lstSelected”);
var len = list.options.length;
var i = 0;
alert(len);
for (i = 0; i < len; i++)
{ if(list.options[i].selected)
{ alert(document.getElementById(“lstSelected”)(i).value); list.options[i]=null;
}
}
}
[/CODE]

I wondered if anyone had any ideas

many thanks

to post a comment
JavaScript

2 Comments(s)

Copy linkTweet thisAlerts:
@tpdietzJan 10.2011 — I think it would help us if you posted the HTML.
Copy linkTweet thisAlerts:
@ninjaimpauthorJan 10.2011 — Here it is;
[CODE]
<head runat="server">
<title>Select Compononents</title>
<script language="javascript" type="text/javascript">
function DeleteItem()
{

var list = document.getElementById("lstSelected");
var len = list.options.length;
var i = 0;
alert(len);

for (i = 0; i < len; i++)
{
if(list.options[i].selected)
{
alert(document.getElementById("lstSelected")(i).value);
list.options[i]=null;
}

}

}
</script>
</head>
<body>
<form id="form1" runat="server" name="F1" >
<div>

<asp:DropDownList ID="drpCompParams" runat="server"
Width="366px">
</asp:DropDownList>
<asp:Button ID="btnFilter" runat="server" Text="Filter" />
&nbsp;<asp:Button ID="btnAdd" runat="server" Text="Add" />
<br />
<asp:ListBox ID="lstComps" runat="server" Height="161px"
SelectionMode="Multiple" Width="653px"></asp:ListBox>
<br />

<br />
<asp:ListBox name="S1" ID="lstSelected" runat="server" Height="117px"
Width="652px" >
</asp:ListBox>
<br />
<br />
<asp:Label ID="Label1" runat="server" Text="Label"></asp:Label>

</div>
</form>
</body>
[/CODE]
×

Success!

Help @ninjaimp spread the word by sharing this article on Twitter...

Tweet This
Sign in
Forgot password?
Sign in with TwitchSign in with GithubCreate Account
about: ({
version: 0.1.9 BETA 5.18,
whats_new: community page,
up_next: more Davinci•003 tasks,
coming_soon: events calendar,
social: @webDeveloperHQ
});

legal: ({
terms: of use,
privacy: policy
});
changelog: (
version: 0.1.9,
notes: added community page

version: 0.1.8,
notes: added Davinci•003

version: 0.1.7,
notes: upvote answers to bounties

version: 0.1.6,
notes: article editor refresh
)...
recent_tips: (
tipper: @AriseFacilitySolutions09,
tipped: article
amount: 1000 SATS,

tipper: @Yussuf4331,
tipped: article
amount: 1000 SATS,

tipper: @darkwebsites540,
tipped: article
amount: 10 SATS,
)...