validations using JQuery or java script

Posted by Praveen7k under jQuery on 3/9/2011 | Points: 10 | Views : 1613 | Status : [Member] | Replies : 3
I have TextBox and a Button asp.net controls

first the button is in disabled position When the user starts typing the text in textbox the button should be enabled

How can i achieve this using JQuery or Java Script




Responses

Posted by: Madhu.b.rokkam on: 3/9/2011 [Member] [MVP] Bronze | Points: 25

Up
0
Down
In page load add this

TextBox1.Attributes.Add("OnKeyUp", "javascript:return fun()");

in javascript add this function

function fun() {

if (document.getElementById("TextBox1").value != "")
document.getElementById("btnCheck").disabled = false;
else
document.getElementById("btnCheck").disabled = true;
return false;
}


This piece of code will enable/disable the button.

Thanks and Regards
Madhu

Praveen7k, if this helps please login to Mark As Answer. | Alert Moderator

Posted by: SurajRane on: 3/10/2011 [Member] Starter | Points: 25

Up
0
Down
You can do this using JQuery also.

write a function like below.

function EnableDisableBtn(txtbox) 

{
if (txtbox.value == "")
$("#btnClick").attr("disabled", "disabled");
else
$("#btnClick").removeAttr("disabled");
}


// here your controls
<input type="text" id="txtbx" onblur="EnableDisableBtn(this)" />

<br />
<input type="button" id="btnClick" value="Click Me" disabled="disabled" />


I have used onblur event. you can use it as per your need.

Note: You have to add reference of "jquery-1.4.1.js" file for jquery.



Praveen7k, if this helps please login to Mark As Answer. | Alert Moderator

Posted by: Praveen7k on: 3/10/2011 [Member] Starter | Points: 25

Up
0
Down
Thanks everyone for the reply..... for this code
When i enter some text in the textbox and i click on the button then it si enabled.
when i remove the text and click on the button it is disabled...

My Problem is i have to disable and enable the button asyncronously.....


Praveen7k, if this helps please login to Mark As Answer. | Alert Moderator

Login to post response