Monday, May 20, 2024
 Popular · Latest · Hot · Upcoming
76
rated 0 times [  77] [ 1]  / answers: 1 / hits: 53770  / 10 Years ago, thu, july 24, 2014, 12:00:00

I'm trying to disable enable a button based on an input type value. Here is the Angular JS html code



<div ng-app>
<form name=myForm ng-controller=ctrl>
<input type=text ng-model=name ng-required=true />
<span>{{name}}</span>
<input type=submit value=Submit ng-disabled=myForm.name.$pristine />
</form>
</div>


And the controller code:



function ctrl($scope){
$scope.name = hello;
}


But the button is not getting disabled no matter what.



Here is the DEMO



NOTE: I want the button to be disabled only when text box doesn't have any value and vice versa


More From » angularjs

 Answers
14

Try this



<input type=submit value=Submit ng-disabled=name==undefined || name=='' />


Hope it helps.....................


[#70058] Wednesday, July 23, 2014, 10 Years  [reply] [flag answer]
Only authorized users can answer the question. Please sign in first, or register a free account.
jameson

Total Points: 534
Total Questions: 103
Total Answers: 102

Location: Lithuania
Member since Fri, Sep 4, 2020
4 Years ago
jameson questions
;