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
    New to the CF scene
    Join Date
    May 2009
    Posts
    2
    Thanks
    0
    Thanked 0 Times in 0 Posts

    passing 1 variable containing 3 parameters

    New to this bare with me.

    Code:
    myfunction(a,b,c)
    {
    do something;
    }
    
    
    <select onChange="myfunction(document.getElementById('selectid').value)">
      <option value="'cool','dude',3">  Hee </option>
      <optiion value="'some','dif',2">  Haa </option>
    </select>

  • #2
    New to the CF scene
    Join Date
    May 2009
    Posts
    2
    Thanks
    0
    Thanked 0 Times in 0 Posts
    I figured a way out, but if there is a better way would like to see that

    Code:
    myfunction(a,b,c)
    {
    do something;
    }
    
    
    <select onChange="eval(document.getElementById('selectid').value)">
      <option value="myfunction('cool','dude',3)">  Hee </option>
      <optiion value="myfunction('some','dif',2")>  Haa </option>
    </select>

  • #3
    Supreme Master coder! Old Pedant's Avatar
    Join Date
    Feb 2009
    Posts
    27,650
    Thanks
    80
    Thanked 4,638 Times in 4,600 Posts
    Not sure it's necessarily better in any way, but:
    Code:
    <select onChange="var e = this.value.split(/::/g);myfunctin(e[0],e[1],parseInt(e[2]);">
      <option value="cool::dude::3">  Hee </option>
      <optiion value="some::dif::2")>  Haa </option>
    </select>
    If this is the only place myfunction is called, I'd just rewrite the function to take the delimited string and do the split inside the function. The choice of delimiter is of course up to you, so long as it doesn't appear in any of the elements.


  •  

    Posting Permissions

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