Click here to Skip to main content
15,896,557 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
Hello programmers, got a problem here. I would like to know if ASP.NEt can create a link between checkbox and textbox where the checkbox will autocheck itself when textbox is filled and the checkbox unchecked when the textbox is being emptied

plss give me tutorial regarding this matter

Thanks and more power
Posted

ASP.NET creates HTML and javascript, which can do this. You need to handle the event of a keypress inside the textbox, and then check the length of the text to check or uncheck. Use the ClientID property of your two controls to emit javascript to do this in to your page.
 
Share this answer
 
Comments
janwel 11-Jul-11 22:24pm    
Sir how can i do that?
Christian Graus 11-Jul-11 22:32pm    
Well, you can put a literal control on the page, build your javascript in your code behind and put it on to the literal to get it on the page. Then you can set the attributes of the controls in your aspx to handle the events, ASP.NET will just pass them through to the page. It's a pretty easy, first time javascript task, if you've not done it before.
janwel 11-Jul-11 22:34pm    
ill try sir ^^ new in javascript ^^
Christian Graus 11-Jul-11 22:35pm    
By all means, if you get stuck, post your code here and we'll be happy to help. We just prefer it if you try it yourself first, that's how you learn :-)
janwel 11-Jul-11 22:54pm    
Sir should i use loopings?
this is javascript code
function check()
{
document.GetElementById("checkboxname").checked = true ;
}

call this method on OnKeyPress or OnKeyDown even of the Textbox

<asp:TextBox ID="txt1" OnKeyPress ="check" OnKeyDown ="check" runat="server">
 
Share this answer
 
Comments
Christian Graus 12-Jul-11 1:26am    
This is close enough to useless as to make no difference. It doesn't check if the text box has text in it, nor does it ever uncheck the checkbox, nor does it look up the client side ID properly.

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900