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
    Feb 2009
    Location
    mumbai
    Posts
    4
    Thanks
    0
    Thanked 0 Times in 0 Posts

    how to pass the array value on change of select box

    Hi,

    I am having one select box, when i will select the value from select box i want to call one java script function and pass the parameter as array of some values to js function.

    Please let me know how to do this.

    Thanks in advance.

  • #2
    Senior Coder
    Join Date
    Jun 2002
    Posts
    1,404
    Thanks
    2
    Thanked 32 Times in 32 Posts
    '...array of some values...' is pretty vague. More details would help.

  • #3
    Senior Coder
    Join Date
    Jun 2002
    Posts
    1,404
    Thanks
    2
    Thanked 32 Times in 32 Posts
    Code:
    <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"
      "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
    <html xmlns="http://www.w3.org/1999/xhtml">
    <head>
    <meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
    <title>untitled</title>
    <script type="text/javascript">
    
    var some_values = {
    			first : ['red', 'white', 'blue'],
    			second : ['small', 'medium', 'large'],
    			third : ['cold', 'warm', 'hot']
    		  }
    
    function some_function(some_arr)
    {
       var x = some_arr.join(' ');
       var span = document.getElementsByTagName('span')[0];
       span.replaceChild(document.createTextNode(x), span.firstChild);
    }
    
    </script>
    </head>
    <body>
    <form>
    <select name="foo" onchange="if(this.value)some_function(some_values[this.value])">
    <option value="">choose</option>
    <option value="first">first</option>
    <option value="second">second</option>
    <option value="third">third</option>
    </select>
    <span id="foo">&nbsp;</span>
    </form>
    </body>
    </html>
    Not sure if that was what you meant. Keep in mind that the passed array will show up as arguments[0] inside the function: arguments is an array itself, and you're just setting its first slot.


  •  

    Posting Permissions

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