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.

1

3 Answers 3

1

add this code in javascript method

function GetValues() {

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

Sign up to request clarification or add additional context in comments.

Comments

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/

2 Comments

It would be helpful if you could provide some sample code here.
the problem is how define lisbox in view and i don't know what can i put inside this:@Html.ListBox()
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 });

            }

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.