Change in Selected Index of List box

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • Vini171285
    New Member
    • Apr 2008
    • 60

    Change in Selected Index of List box

    Hi,
    How can we place a particular value in text box depending on change in index of a list box..
    Can someone give me a small example..for doing this..
    Thanx..
  • DrBunchman
    Recognized Expert Contributor
    • Jan 2008
    • 979

    #2
    Hi Vini,

    If you have a form which looks like this:
    [HTML] <form name="TestForm" >
    <select name="cboTest" onchange="displ ayvalue();">
    <option value="1">Optio n 1</option>
    <option value="2">Optio n 2</option>
    </select>
    <input type="text" name="txt1" />
    </form>[/HTML]
    You can use the following javascript function to populate the text box with the selected value:
    Code:
     
     <script type="text/javascript">
     function displayvalue()
     {
     document.TestForm.txt1.value = document.TestForm.cboTest.options[document.TestForm.cboTest.selectedIndex].value
     } 
     </script>
    You'll need to place the script inside the head tags of your page and change the names of the form and controls as appropriate. Hopefully you can see how this function works: when you change the item in the list box the OnChange event fires and loads the function which sets the value of the specified textbox to the value of the selected item.

    Let me know how you get on,

    Dr B

    Comment

    • Vini171285
      New Member
      • Apr 2008
      • 60

      #3
      Hi,
      This code is working ..
      Thanx..
      actually i am filling a list box from database and depending on change in that list box ,the value corresponding to that selected index should come in the textbox,which should come from another column of the table in database..
      Thanx..

      Comment

      • DrBunchman
        Recognized Expert Contributor
        • Jan 2008
        • 979

        #4
        Answered here.

        Dr B

        Comment

        Working...