I have been trying to push array values from multiple select dropdown into text box on clicking "Add" using getElementById
<!DOCTYPE html>
<html>
<body>
TextName: <input type="text" id="txtName" readonly="readonly" />
Name:<select multiple="" name="ddlNames[]" id="ddlNames">
<option value="Mudassar Khan">Mudassar Khan</option>
<option value="John Hammond">John Hammond</option>
<option value="Mike Stanley">Mike Stanley</option>
</select>
<button onclick="SetName()">Add</button>
<script>
function SetName() {
var txtName = document.getElementById("txtName");
txtName.value = document.getElementById("ddlNames[]").value;
}
</script>
</body>
</html>
The above code outputs only the first selected option to the textbox but not all the selected options.Any suggestions on what I am doing wrong? Or what I can change?