2

I have a select list and need to append each selected value/text to a list on a button click. Here is some pseudo code

  $("#addButton").click(function () {           

            var selectedValue = "..."
            var selectedText = "..."

            //todo append each selected value & text
            //to an unordered list 
            //on submit of form read in via querystring selected
            //values and text from the unordered list

}); 

Any ideas?

Thanks

1 Answer 1

6
$("#addButton").click(function () {           

  var selectedVal = $('select').val();

  $('ul').append('<li>'+selectedVal+'</li>')

}); 

JSFiddle

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

4 Comments

It appears the text of the selected option is also needed. In that case: $("#mySelectList option:selected").text();
Thanks for the reply. However how would I read in via querystring each value and text in the unordered list? I guess I would need to loop through the it?
@DreamToCode to have it sent on a submitted form you have to add the values to hidden input in addition to adding it to the list.
Ok thanks Shadow Wizard. So I guess I would have an array of hidden input fields?

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.