Hello and welcome to our community! Is this your first visit?
Register
Enjoy an ad free experience by logging in. Not a member yet? Register.
Results 1 to 3 of 3
  1. #1
    Senior Coder xelawho's Avatar
    Join Date
    Nov 2010
    Posts
    3,020
    Thanks
    56
    Thanked 566 Times in 563 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
    Senior Coder Logic Ali's Avatar
    Join Date
    Sep 2010
    Location
    London
    Posts
    1,028
    Thanks
    0
    Thanked 207 Times in 202 Posts
    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>

  • Users who have thanked Logic Ali for this post:

    xelawho (09-05-2011)

  • #3
    Senior Coder xelawho's Avatar
    Join Date
    Nov 2010
    Posts
    3,020
    Thanks
    56
    Thanked 566 Times in 563 Posts
    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; 09-05-2011 at 03:42 AM.


  •  

    Posting Permissions

    • You may not post new threads
    • You may not post replies
    • You may not post attachments
    • You may not edit your posts
    •