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

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

P: 24
Hi all. I need help about this particular aspect.

In a webform I have an <asp:textbox> (txtName) and <asp:DropDownList> (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.
Jan 8 '09 #1
Share this Question
Share on Google+
6 Replies


Expert 100+
P: 392
@uicouic
Expand|Select|Wrap|Line Numbers
  1.  
  2. <html>
  3.     <body><br /><br />
  4.  
  5.         <select onchange="concatInput()" id="dropDownMenu" >
  6.             <option value="1" >1</option>
  7.             <option value="2" >2</option>
  8.             <option value="3" >3</option>
  9.         </select>
  10.  
  11.         <br /><br />        
  12.  
  13.         <input type="text" id="feildInput" />
  14.  
  15.  
  16.         <script>
  17.            function concatInput() {
  18.  
  19.                 var fieldOne = document.getElementById('dropDownMenu');
  20.                 var fieldTwo = document.getElementById('feildInput');
  21.                 var conCatinatedVal = fieldOne[fieldOne.selectedIndex].value  + fieldTwo.value;
  22.  
  23.                 alert('  New Contactinated String : '+conCatinatedVal);
  24.  
  25.             }
  26.         </script>
  27.     </body>
  28. </html>
  29.  
  30.  
Jan 9 '09 #2

P: 24
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:DropDownList> instead. Could you advise me on how to modify the above code? Thanks.
Jan 14 '09 #3

acoder
Expert Mod 15k+
P: 16,027
If you check the source of the generated code, you will see that it's converted to HTML.
Jan 14 '09 #4

P: 24
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.

Expand|Select|Wrap|Line Numbers
  1. lstBox.attributes.add("onchange","concatInput( )")
or is there another way going about it?

Please advise, thanks.
Jan 15 '09 #5

acoder
Expert Mod 15k+
P: 16,027
Yes, that seems to be the way. If you still have problems with it, try asking in the ASP.NET forum.
Jan 15 '09 #6

P: 24
Ok I'll do just that.

Thanks acoder. :)
Jan 16 '09 #7

Post your reply

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