By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
445,824 Members | 1,247 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 445,824 IT Pros & Developers. It's quick & easy.

select value from a combobox and display in a textbox

100+
P: 274
hi,
I have a simple query. I have a dynamic combobox when I select one value fromt he combobox; on click a function is called that display the value of the combobox(i.e not same as text list of combobox) in textbox on the form.
I want to display the selected entry(not the value) of the combobox in another text box. How I can do that
this is what I already have
Expand|Select|Wrap|Line Numbers
  1. function getvalue(form)
  2.        {
  3.          form.clientID.value=form.clientName.value;
  4.          form.ClientName.value=form.clientName.selected; // whatever is there is combobox display it textbox called ClientName.
  5.        }
  6.  
Jun 5 '08 #1
Share this Question
Share on Google+
7 Replies


eWish
Expert 100+
P: 971
I am not familiar with VB, but this looks like VB code and therefore should belong in that forum. If I am correct on the code I will move this post for you.

--Kevin
Jun 6 '08 #2

100+
P: 274
it's javascript. you cam move it there.
Jun 6 '08 #3

gits
Expert Mod 5K+
P: 5,378
you should post the relevant html-code too, so that we may see whether the ids and names are correct. you may even consider to use dom-methods like document.getElementById(); for your node-references ...

kind regards
Jun 6 '08 #4

100+
P: 274
I got it working thanks
Jun 10 '08 #5

acoder
Expert Mod 15k+
P: 16,027
That's good to hear, but it's always courteous to post how you solved it for the benefit of others.
Jun 11 '08 #6

100+
P: 274
I used a very simple technique:
I used BEAN to get value of the table client and displayed clientName as text of the combobox and used clientID as the value of the combo.

Expand|Select|Wrap|Line Numbers
  1. <select name="clientName" id ="clientName" onChange="getvalue(this.form)">   
  2.     <% java.util.Vector clients = (java.util.Vector)session.getAttribute("clients");
  3.     if(clients != 
  4.                { // start of if1
  5.                           for (int i =0; i<clients.size(); i++)
  6.                           { //start of for1
  7.                             Client client = (Client)clients.get(i
  8.               if(client instanceof Client)
  9.                {// start of if2
  10.                  %>
  11.           <option value=<%= client.getClientID() %>>
  12.                          <%= client.getClientName() %>  </option>
  13.             <%
  14.      }// end of if2
  15.               }// end if for1
  16.            }// end of if1
  17.         %>
  18.  
  19.             </select> 

Again in the function getvalue() I tried something like this

Expand|Select|Wrap|Line Numbers
  1. function getvalue(form)
  2.        {
  3.          form.clientID.value=form.clientName.value;
  4.        }

It works fine and good thing is it's easy.
Regards
Jun 16 '08 #7

acoder
Expert Mod 15k+
P: 16,027
Thanks for posting the solution.
Jun 16 '08 #8

Post your reply

Sign in to post your reply or Sign up for a free account.