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

Add Listbox

Question posted by: silvia21 (Newbie) on March 28th, 2008 07:17 AM
I am using ASP and Javascript. I created one list box. if i select one value that value is added in next text box. i wrote coding. but some errors. value is not added. that sample coding is:

<script type="text/javascript">
function addBank()
{
option=document.jaldi[0].lender.options[document.jaldi[0].lender.selectedIndex].text
txt=document.jaldi[0].bank.value
txt=txt + option
document.jaldi[0].bank.value=txt
}
<script>
<form method="post" name="jaldi" id="jaldi">
Available Banks <select name="lender">
<option value="AXIS Bank">AXIS Bank</option>
<option value="Bank of Baroda">Bank of Baroda</option>
<option value="Citi Bank">Citi Bank</option>
</select>

<input type="button" value="Add" onClick="addBank()">

Selected Bank <input name="bank" type="text">

plz help me for this coding. i didnt get answer. plz tell wat error
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
555 Posts
March 28th, 2008
09:48 AM
#2

Re: Add Listbox
Hi silvia21,

There are a couple of problems with your javascript. You haven't declared the variables (option & txt) and there was an error with the way you were referring to your controls. Also you hadn't put a backslash in your closing <script> tag.

If you change your javascript function to the following:
Code: ( text )
  1. <script type="text/javascript">
  2. function addBank()
  3. {
  4. var option = document.jaldi.lender.options[document.jaldi.lender.selectedIndex].text
  5. var txt=document.getElementById('bank');
  6. txt.value=option;
  7. }
  8. </script>

It should work for you. Let me know how you get on.

Hope this helps,

Dr B

Reply
Reply
Not the answer you were looking for? Post your question . . .
169,970 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