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 2 of 2
  1. #1
    New Coder
    Join Date
    Mar 2006
    Posts
    93
    Thanks
    3
    Thanked 0 Times in 0 Posts

    Question Get value of selected option in a multiple select box

    Hi,

    i have a multiple select box

    Code:
    <select onchange='getvalue(this)' class=textField multiple size="5" id="fenetre" name="fenetre">
    and a function :
    [CODE]function getvalue(nom)
    {
    var selectedValue=nom.value;
    alert(selectedValue);
    }CODE]

    my problem is the following :

    when i click on an option in the select box, the alert always shows me the first option that is selected. For example, if i click the third option and the first option is already selected, the alert shows the value of the first option when i want to know which option the user has just clicked.

    Thanks

  • #2
    New to the CF scene
    Join Date
    Apr 2007
    Posts
    6
    Thanks
    0
    Thanked 0 Times in 0 Posts
    Code:
    <select onchange='getvalue(this)' class=textField multiple size="5" id="fenetre" name="fenetre">
    <option value="1">1</option>
    <option value="2">2</option>
    <option value="3">3</option>
    </select>
    <script type="text/javascript">
    //<![CDATA[
    function getvalue(nom)
    {
      var a=nom; var result=[];
      for (var i=0; i<a.length; i++) {
        a[i].selected?result.push(a[i].value):"";
      }
      result?new function(){
        alert("the result is: " +result);
        alert("now you select the value is: " +result.reverse().slice(0,1));
      }:"";
    
    }
    //]]>
    </script>


  •  

    Posting Permissions

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