r code
r code

Reputation: 7

How define listbox in view asp.net and add items

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.

Upvotes: 0

Views: 150

Answers (3)

razzek
razzek

Reputation: 609

add this code in javascript method

function GetValues() {

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

Upvotes: 1

razzek
razzek

Reputation: 609

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 });

            }

Upvotes: 1

Tudnor
Tudnor

Reputation: 31

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/

Upvotes: 1

Related Questions