1

Here is my code i am struggling with the multiple values select with jquery if i will select two values i should get two values in the function test

<html>
<select name="hello[]" id="hello" multiple="multiple" onchange="test(this.value);">
<option value="">Select Value</option>
<option value="1">PHP</option>
<option value="2">JAVA</option>
<option value="3">.NET</option>
<option value="4">ORACLE</option>
<option value="5">DBA</option>
</select>
</html>
<script>
function test(xx)
{

alert(xx);
}

please help me

Vamshi .goli
  • 522
  • 4
  • 13

2 Answers2

1

Try the below code similar to your approach

<script>
var hello = new Array(); 
function test(xx)
{
  hello.push(xx);
  alert(hello);
}
</script>
manuyd
  • 201
  • 1
  • 8
0

Try removing this:

onchange="test(this.value);"

and jQuery:

var test = function(x) {
   alert(x);
}

$(document).on('change', '#hello', function() {
       var val = $(this).val();
       test(val);
});

or more compact:

$(document).on('change', '#hello', function() {
       var val = $(this).val();
       alert(val);
});

Check the DEMO

kapantzak
  • 11,610
  • 4
  • 39
  • 61