MrSolution MrSolution - 5 months ago 7
Javascript Question

How can I check if the text of an input field is "yes" or "no"?

I want to check if the text from an input field is "yes" or "no". Is it possible to do this with

ng-click
?

<div class="cClearFloat cInputSpace">
<input placeholder="login" ng-model="currentUser.login">
</div>
<div class="cClearFloat cInputSpace">
<input placeholder="Vorname" ng-model="currentUser.Vorname">
</div>
<div class="cClearFloat cInputSpace">
<input placeholder="Nachname" ng-model="currentUser.Nachname">
</div>
<div class="cClearFloat cInputSpace">
<input placeholder="password" ng-model="currentUser.password">
</div>
<div class="cClearFloat cInputSpace">
<input placeholder="Admin" ng-model="currentUser.isAdmin">
</div>
<div class="cClearFloat cButtonsUser">
<button class="cButtonSpeichern" ng-click="saveUser()">Speichern</button>
<button class="cButtonAbbrechen" ng-click="isShownUser= false">Abbrechen</button>
</div>
</div>


These are the input fields and when I press on the button "Speichern", I want to check it.

Answer

I made it like this and it works!

JavaScript:

    $scope.showAlert = function() {
        //überprüfen ob die textfelder leer sind
        if ($scope.currentUser.isAdmin == 'Ja' | $scope.currentUser.isAdmin == 'ja') {
            $scope.isAdmin = "Ja";
            $scope.saveUser();
        } else if($scope.currentUser.isAdmin == 'Nein' | $scope.currentUser.isAdmin == 'nein') {
            $scope.isAdmin = "Nein";
            $scope.saveUser();
        } else {
            alert("Bitte geben Sie ein ob der Benutzer ein Admin ist oder nicht!", "Fehler");
        }
    }

HTML:

     <button class="cButtonSpeichern" ng-click="showAlert()">Speichern</button>

but thank you for your help guys!

Comments