how to get item name in combo or list box from its index using php.here i try in js

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • harini0590
    New Member
    • Apr 2012
    • 19

    how to get item name in combo or list box from its index using php.here i try in js

    but this doesn't give answer....
    Code:
    function fun_month()
    {
    var temp = document.getElementById("list_month").selectedIndex;
    alert(temp);
    
    selected_month = document.getElementById("list_month").options[temp].value;
    
    alert(selected_month);
    }
  • Rabbit
    Recognized Expert MVP
    • Jan 2007
    • 12517

    #2
    Why are you giving us javascript if you're trying to do it in PHP? Where's your PHP code?

    Just so you know, you can't really do this in PHP. But why would you want to? What's the point of passing the selected index to PHP when you can just pass the selected value?

    Comment

    • johny10151981
      Top Contributor
      • Jan 2010
      • 1059

      #3
      in a combo box there is two thing
      1. the value and
      2. the text
      Code:
      <select id='dd'>
       <option value='1'>111</option>
       <option value='2'>222</option>
      </select>
      if you do
      document.getEle mentById('dd'). value
      you would get either 1 or 2.

      your form would send the value of selected item to server.

      Comment

      • harini0590
        New Member
        • Apr 2012
        • 19

        #4
        i want to get value so i try to get index and then by using that index i want to get a value so only i raise a question..
        johny give a exact answer for that thanks...
        but using index too, i get value..
        but johny method is simple..

        Comment

        Working...