0

I have to select multiple values from a drop down and display it in text area on click of a submit. I do not know how to pass multiple values to controller and fetch it to display in a text area in same form....

Anshul
  • 1
  • 2
  • 10

1 Answers1

0

You can use the multiple attribute of the html select element and angular will create an array for you of the selected values:

angular.module('MyModule', [])

.controller('MyController', function( $scope ) {
    $scope.martialArts = ['Kung Fu', 'Llap Goch', 'Karate', 'Judo'];
});
<script src="https://ajax.googleapis.com/ajax/libs/angularjs/1.2.23/angular.min.js"></script>

<div ng-app='MyModule' ng-controller='MyController'>
    I know
    <select multiple ng-model='whatIKnow' ng-options='martialArt for martialArt in martialArts'></select>
    <button ng-click='showWhatIKnow = true'>Show Me</button>
    <textarea ng-show='showWhatIKnow' ng-model='whatIKnow'></textarea>
</div>
Gruff Bunny
  • 27,738
  • 10
  • 72
  • 59
  • when i am using above code it is displaying [object Object] in the text area.if i am selecting two values then it showing two times [object Object]. – Anshul Nov 03 '14 at 10:57
  • How strange. Which browser are you using (if I run the code snippet in Chrome 38 it looks ok)? – Gruff Bunny Nov 03 '14 at 12:19
  • I am using fire fox version 34. – Anshul Nov 03 '14 at 12:24
  • Have only got firefox 33 but if I run the above code by pressing the 'Run code snippet' then it works as expected. Are you running the above code by pressing the 'Run code snippet' button or is it your own code that's based on the above? – Gruff Bunny Nov 03 '14 at 12:31
  • it is my code based on the above code.it is still showing [object Object].. please help @Gruff Bunny – Anshul Nov 04 '14 at 05:16
  • actually i am fetching the values from the data base than giving hard code values in array.....is that creating the problem..?? – Anshul Nov 04 '14 at 05:20
  • I suspect that you have an array of objects and not strings. The answers to this question may help: http://stackoverflow.com/questions/17893708/angularjs-textarea-bind-to-json-object-shows-object-object – Gruff Bunny Nov 04 '14 at 08:27