Login or Sign up Help | Site Map
Connecting Tech Pros Worldwide

Change in Selected Index of List box

Question posted by: Vini171285 (Member) on April 30th, 2008 07:48 AM
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..
Would you like to answer this question?
Sign up for a free account, or Login (if you're already a member).
DrBunchman's Avatar
DrBunchman
Moderator
556 Posts
April 30th, 2008
10:27 AM
#2

Re: Change in Selected Index of List box
Hi Vini,

If you have a form which looks like this:
Code: ( text )
  1. <form name="TestForm">
  2.   <select name="cboTest" onchange="displayvalue();">
  3.    <option value="1">Option 1</option>
  4.    <option value="2">Option 2</option>
  5.   </select>
  6.   <input type="text" name="txt1" />
  7.  </form>

You can use the following javascript function to populate the text box with the selected value:
Code: ( text )
  1. <script type="text/javascript">
  2.  function displayvalue()
  3.  {
  4.  document.TestForm.txt1.value = document.TestForm.cboTest.options[document.TestForm.cboTest.selectedIndex].value
  5.  }
  6.  </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

Reply
Vini171285's Avatar
Vini171285
Member
60 Posts
April 30th, 2008
12:17 PM
#3

Re: Change in Selected Index of List box
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..

Reply
DrBunchman's Avatar
DrBunchman
Moderator
556 Posts
May 12th, 2008
03:24 PM
#4

Re: Change in Selected Index of List box
Answered here.

Dr B

Reply
Reply
Not the answer you were looking for? Post your question . . .
170,099 Experts ready to help you find a solution.
Sign up for a free account, or Login (if you're already a member).

Top ASP Forum Contributors