Web Analytics Made Easy -
StatCounter calling separate functions from a select list - CodingForum

Announcement

Collapse
No announcement yet.

calling separate functions from a select list

Collapse
X
 
  • Filter
  • Time
  • Show
Clear All
new posts

  • calling separate functions from a select list

    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:

    Code:
    <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>
    	</select>
    is it possible?

  • #2
    Assuming the functions are global:
    Code:
    <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>
    </select>

    Comment


    • #3
      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

      EDIT2: thanks, Ali!
      Last edited by xelawho; Sep 4, 2011, 09:42 PM.

      Comment

      Working...
      X
      😀
      🥰
      🤢
      😎
      😡
      👍
      👎