Java script enabled textbox

  • Thread starter Thread starter GMK
  • Start date Start date
G

GMK

dear all
i'm building an asp.net application i have on one of my pages a checkbox i
want that whenever the user checkd the checkbox to enable a textbox and when
the user uncheck the checkbox the textbox will be diabled.
i want to make those action on client side.
so if anyone could provide me the code i would be so thankful
thank you
 
Something like this:

<input type="checkbox" id="x" onClick="ToggleInput(this, 'username');" >
<input type="text" id="username" >

<script language="javascript">
function ToggleInput(check, txtBox){
var txt = document.getElementById(txtBox);
txt.disabled = !(check.checked);
}
</script>

??

Karl
 
I tried this peace of code it worked correctly with an asp file but when i
tried to use it in an aspx page it gave me a JScript rintime error.
i'm using asp.net 1.1
does all javasscript syntax compatible with asp.net 1.1
 
Hi GMK,

do the following
Add the OnClick event OnClick="ToggleTextbox();"

e.g

<asp:CheckBox id="CheckBox1" OnClick="ToggleTextbox();" runat="server"
</asp:CheckBox>


and then in the script tag

<script>
function ToggleTextbox()
{
if (document.Form1.CheckBox1.checked == true)
document.Form1.TextBox1.disabled = false;
else
document.Form1.TextBox1.disabled = true;
}
</script>
considering that the Id of textbox that you want to disable is TextBox1



***********************************
Hope this helps
Shaun (M.C.P)

http://blogs.wwwcoder.com/shaunakp
***********************************
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Back
Top