View Full Version : calling separate functions from a select list

09-05-2011, 01:48 AM
so, I can pass a value from a select list to another function which then decides which function to call, but I want to cut out the middleman, and make the values the function calls, and call them directly on the onchange... I imagine something like this:

<select id="select" onchange="this.value">
<option selected value="function1()">Funtion 1</option>
<option value="function2()">Function 2</option>
<option value="function3()">Function 3</option>

is it possible?

Logic Ali
09-05-2011, 02:35 AM
Assuming the functions are global:

<select id="select" onchange="if( this.value ){ window[ this.value ]() }" >
<option value=""> Select </option>
<option value="function1">Funtion 1</option>
<option value="function2">Function 2</option>
<option value="function3">Function 3</option>

09-05-2011, 03:39 AM
yep, they're global, but that gives me:
window[this.value] is not a function

EDIT: forgot to take out the brackets. back in a minute :D

EDIT2: thanks, Ali!