View Full Version : how to pass the array value on change of select box

05-13-2009, 10:44 AM

I am having one select box, when i will select the value from select box i want to call one java script function and pass the parameter as array of some values to js function.

Please let me know how to do this.

Thanks in advance.

05-13-2009, 10:53 AM
'...array of some values...' is pretty vague. More details would help.

05-13-2009, 01:15 PM
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"
<html xmlns="http://www.w3.org/1999/xhtml">
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<script type="text/javascript">

var some_values = {
first : ['red', 'white', 'blue'],
second : ['small', 'medium', 'large'],
third : ['cold', 'warm', 'hot']

function some_function(some_arr)
var x = some_arr.join(' ');
var span = document.getElementsByTagName('span')[0];
span.replaceChild(document.createTextNode(x), span.firstChild);

<select name="foo" onchange="if(this.value)some_function(some_values[this.value])">
<option value="">choose</option>
<option value="first">first</option>
<option value="second">second</option>
<option value="third">third</option>
<span id="foo">&nbsp;</span>

Not sure if that was what you meant. Keep in mind that the passed array will show up as arguments[0] inside the function: arguments is an array itself, and you're just setting its first slot.