0

I have an input type text and a button in an asp.net page and I want to add a Listbox to the page. I also want to add the value of the textbox to the Listbox when I click the button

<button id="ajouter"   type="button" >Ajouter au panier</button>
<input class="text" id="Num" type="text" name="Num" />

Can someone help me and explain how to define listbox in the page and how to add the text from the textbox to the listbox when the button is clicked.

S.Dav
  • 2,436
  • 16
  • 22
r code
  • 7
  • 4
  • [how to define listbox in the view](http://www.codeproject.com/Articles/771999/ASP-Net-MVC-How-to-create-a-ListBox) – pravprab Dec 28 '15 at 09:48

3 Answers3

1

If you don't want to remember the data just list it temporary try with jQuery.

  1. How to get the value: How do I get the value of a textbox using jQuery?
  2. How to insert a new element: http://api.jquery.com/append/
Community
  • 1
  • 1
Tudnor
  • 31
  • 3
1

that's the definition of list and the button :

Ajouter au panier

and now this is the javascript code :

 function GetValues() {
                debugger;
                var myList = $("#multiSelect");
                var yy = $("#idtext2").val();

                var Selectedelement = $("#idtext").val();

                myList.append('<option value=' + Selectedelement + '>' + Selectedelement + " " + yy + '</option>');
                global.push({ "id": yy, "qte": Selectedelement });

            }
razzek
  • 595
  • 7
  • 23
1

add this code in javascript method

function GetValues() {

....................... myList.append(''+ Selectedelement +''); ...............
}

razzek
  • 595
  • 7
  • 23