select value from a combobox and display in a textbox

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • creative1
    Contributor
    • Sep 2007
    • 274

    select value from a combobox and display in a textbox

    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
    Code:
    function getvalue(form)
    	   {
    	     form.clientID.value=form.clientName.value;
    	     form.ClientName.value=form.clientName.selected; // whatever is there is combobox display it textbox called ClientName.
    	   }
  • eWish
    Recognized Expert Contributor
    • Jul 2007
    • 973

    #2
    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

    Comment

    • creative1
      Contributor
      • Sep 2007
      • 274

      #3
      it's javascript. you cam move it there.

      Comment

      • gits
        Recognized Expert Moderator Expert
        • May 2007
        • 5388

        #4
        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.getEle mentById(); for your node-references ...

        kind regards

        Comment

        • creative1
          Contributor
          • Sep 2007
          • 274

          #5
          I got it working thanks

          Comment

          • acoder
            Recognized Expert MVP
            • Nov 2006
            • 16032

            #6
            That's good to hear, but it's always courteous to post how you solved it for the benefit of others.

            Comment

            • creative1
              Contributor
              • Sep 2007
              • 274

              #7
              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.

              Code:
              <select name="clientName" id ="clientName" onChange="getvalue(this.form)">   
                  <% java.util.Vector clients = (java.util.Vector)session.getAttribute("clients");
              	if(clients != 
                             { // start of if1
                                        for (int i =0; i<clients.size(); i++)
                                        { //start of for1
                                          Client client = (Client)clients.get(i
                            if(client instanceof Client)
                             {// start of if2
                               %>
                        <option value=<%= client.getClientID() %>>
                                       <%= client.getClientName() %>  </option>
                          <%
              	 }// end of if2
                            }// end if for1
                         }// end of if1
                      %>
              
                          </select>

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

              Code:
              function getvalue(form)
              	   {
              	     form.clientID.value=form.clientName.value;
              	   }

              It works fine and good thing is it's easy.
              Regards

              Comment

              • acoder
                Recognized Expert MVP
                • Nov 2006
                • 16032

                #8
                Thanks for posting the solution.

                Comment

                Working...