Click to See Complete Forum and Search --> : dropdown array???


squarefish
05-01-2003, 08:24 AM
I'm trying to write a script that changes the content of a layer depending on the selection from a dropdown menu.
I have an array called content[6] which holds the info to be displayed, and a function which changes the displayed info, the function is call (imaginativley)

changetext(whichcontent)

And the value of whichcontent will be 0 to 6 to pick up the item in the array.

I need to call this from the <select> so I have this

<select name="menu1" class=dropdown onchange="javascript:changetext(content['+this+'])">

<option value="0">Option 1</option>
<option value="1">Option 2</option>
<option value="2">Option 3</option>
etc...
</select>

I know my function changetext() works, but when I call it from the selected option I just get "undefined"

I think the problem is with

onchange="javascript:changetext(content['+this+'])"

Richard

pyro
05-01-2003, 08:35 AM
Try doing it like this:

<select name="menu1" class=dropdown onchange="changetext(content['+this.selectedIndex+'])">

<option value="0">Option 1</option>
<option value="1">Option 2</option>
<option value="2">Option 3</option>
etc...
</select>

squarefish
05-01-2003, 08:56 AM
Nope

Still getting undefined?

do I have the syntax correct??

onchange="changetext(content['+this.selectedindex+'])"

pyro
05-01-2003, 09:04 AM
Try removing your '+ +' and let me know what you get. Like this:

onchange="changetext(content[this.selectedindex])"

squarefish
05-01-2003, 09:25 AM
nope still the same

pyro
05-01-2003, 10:27 AM
This works...

<html>
<head>
<script language="javascript" type="text/javascript">
function changetext(whichcontent) {
var content = new Array("one", "two", "three");
alert (content[whichcontent]);
}
</script>
</head>
<body>
<form name="myform">
<select name="menu1" class=dropdown onchange="changetext(this.selectedIndex)">
<option value="0">Option 1</option>
<option value="1">Option 2</option>
<option value="2">Option 3</option>
</select>
</form>
</body>
</html>