Sunday, June 2, 2024
 Popular · Latest · Hot · Upcoming
38
rated 0 times [  41] [ 3]  / answers: 1 / hits: 45817  / 15 Years ago, mon, november 30, 2009, 12:00:00

I have two textboxes tbxProdAc and txtbxHowMany. I would like to write a bit of code in the code behind so that when I enter text in one, any text that may have been in the other is removed.


How would one go about achieving this and in which event should I place it?


I have tried to use:


txtbxHowMany.Attributes.Add("onclick", "document.getElementById('tbxProdAC').innerText='';");

in the page load event but without success; should this be in the pre_init?


As you can probably tell, complete novice at work here.


More From » dom-events

 Answers
21

First off, make sure that when the page has been generated that the ID is still tbxProdAC if this is a .Net control, the ID would have been changed. In this case you can use a class.



Try the following, - This uses JQuery - you will need to include that



txtbxHowMany.Attributes.Add(onclick, $('#tbxProdAC').val('');); 


Add the following to the Head Section of your page.



 <script type=text/javascript src=jquery.js></script> 


And you can get the JQuery.Js file from here: http://docs.jquery.com/Downloading_jQuery#Download_jQuery



And Why: https://stackoverflow.com/questions/308751/why-use-jquery


[#98193] Wednesday, November 25, 2009, 15 Years  [reply] [flag answer]
Only authorized users can answer the question. Please sign in first, or register a free account.
armandoh

Total Points: 208
Total Questions: 94
Total Answers: 112

Location: South Sudan
Member since Sun, Jul 11, 2021
3 Years ago
;