Click here to Skip to main content
11,705,762 members (57,642 online)
Rate this: bad
good
Please Sign up or sign in to vote.
See more: ASP.NET Javascript
Can any one please tell me in ASP.NET How to ADD or REMOVE text box value to List Box item using Add and Remove buttons this should be done using Java script only without server post back.
 
This is my code, but its not working.
 
ASPX :-
<input type="button" value="Add Item" onclick="javascript:addValue()" />
<input type="button" value="Delete Item" onclick="javascript:deleteValue()" />
 <asp:TextBox ID="txtValue" runat="server"></asp:TextBox>
<asp:ListBox ID="LstChanelType" runat="server"></asp:ListBox>
 

Javascript :-
<script type="text/javascript">
var i = 0;
function addValue() {
var v = document.form1.txtChanelType.value;
// get the TextBox Value and assign it into the variable
AddOpt = new Option(v, v);
document.form1.LstChanelType.options[i++] = AddOpt;
return true;
}
function deleteValue() {
var s = 1;
var Index;
if (document.form1.LstChanelType.selectedIndex == -1) {
alert("Please select any item from the ListBox");
return true;
}
while (s >
Posted 6-Aug-14 2:54am

1 solution

Rate this: bad
good
Please Sign up or sign in to vote.

Solution 1

Issue has been fixed
<script type="text/javascript">
var i = 0;
function addValue() {
// alert("Hi");
var v = document.getElementById("MainContent_txtValue").value;
// alert(v);
// get the TextBox Value and assign it into the variable
AddOpt = new Option(v, v);
document.getElementById("MainContent_LstChanelType").options[i++] = AddOpt;
//document.form1.LstChanelType.options[i++] = AddOpt;
return true;
}

function deleteValue() {
var s = 1;
var Index;

if(document.getElementById("MainContent_LstChanelType").selectedIndex == -1)
{
alert("Please select any item from the ListBox");
return true;

}</script>
  Permalink  

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)

  Print Answers RSS
0 OriginalGriff 208
1 Sergey Alexandrovich Kryukov 142
2 Inimicos 60
3 ppolymorphe 57
4 ProgramFOX 50
0 OriginalGriff 9,037
1 Sergey Alexandrovich Kryukov 8,417
2 CPallini 5,189
3 Maciej Los 4,726
4 Mika Wendelius 3,626


Advertise | Privacy | Mobile
Web02 | 2.8.150819.1 | Last Updated 6 Aug 2014
Copyright © CodeProject, 1999-2015
All Rights Reserved. Terms of Service
Layout: fixed | fluid

CodeProject, 503-250 Ferrand Drive Toronto Ontario, M3C 3G8 Canada +1 416-849-8900 x 100