Selecting a value of ASP:DropDownList to concatenate with another String in a textbox

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • uicouic
    New Member
    • Jan 2009
    • 24

    Selecting a value of ASP:DropDownList to concatenate with another String in a textbox

    Hi all. I need help about this particular aspect.

    In a webform I have an <asp:textbox> (txtName) and <asp:DropDownLi st> (lstSchool) with 2 values inside.

    I have typed in a value for the textbox. When I select an option from the dropdownlist, I would like that value(String) to be concatenated with the textbox's value. How do I achieve this in JavaScript?
    (Microsoft Visual Studio 2005)

    Any help/advice appreciated. Thanks.
  • pronerd
    Recognized Expert Contributor
    • Nov 2006
    • 392

    #2
    Originally posted by uicouic
    I would like that value(String) to be concatenated with the textbox's value. How do I achieve this in JavaScript?
    Code:
    <html>
        <body><br /><br />
            
            <select onchange="concatInput()" id="dropDownMenu" >
                <option value="1" >1</option>
                <option value="2" >2</option>
                <option value="3" >3</option>
            </select>
            
            <br /><br />        
            
            <input type="text" id="feildInput" />
            
    
            <script>
               function concatInput() {
                 
                    var fieldOne = document.getElementById('dropDownMenu');
                    var fieldTwo = document.getElementById('feildInput');
                    var conCatinatedVal = fieldOne[fieldOne.selectedIndex].value  + fieldTwo.value;
                
                    alert('  New Contactinated String : '+conCatinatedVal);
                
                }
            </script>
        </body>
    </html>

    Comment

    • uicouic
      New Member
      • Jan 2009
      • 24

      #3
      I appreciate your response but Im not sure what you mean by that, since Im not using HTML tags for the dropdownlist, Im using <asp:DropDownLi st> instead. Could you advise me on how to modify the above code? Thanks.

      Comment

      • acoder
        Recognized Expert MVP
        • Nov 2006
        • 16032

        #4
        If you check the source of the generated code, you will see that it's converted to HTML.

        Comment

        • uicouic
          New Member
          • Jan 2009
          • 24

          #5
          Bummer I can't get it work. :(
          Do I need to assign an attribute to the DropDownList so I can call the function? e.g.

          Code:
          lstBox.attributes.add("onchange","concatInput( )")
          or is there another way going about it?

          Please advise, thanks.

          Comment

          • acoder
            Recognized Expert MVP
            • Nov 2006
            • 16032

            #6
            Yes, that seems to be the way. If you still have problems with it, try asking in the ASP.NET forum.

            Comment

            • uicouic
              New Member
              • Jan 2009
              • 24

              #7
              Ok I'll do just that.

              Thanks acoder. :)

              Comment

              Working...