...

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



yogeshmurkute
05-13-2009, 10:44 AM
Hi,

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.

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

adios
05-13-2009, 01:15 PM
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"
"http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>untitled</title>
<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);
}

</script>
</head>
<body>
<form>
<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>
</select>
<span id="foo">&nbsp;</span>
</form>
</body>
</html>


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.



EZ Archive Ads Plugin for vBulletin Copyright 2006 Computer Help Forum