Hy guys i have found one proble in my application which is related to angularjs.
I have two textbox , if i enter in first textbox the second textbox will be fill automatically.
which i done with simple javascript.
In second textbox i used angularjs validation.
All are required fill.
Once all the fields fill the form will be validate and button will get enable.
But i dnt want to enter in second textbox i will enter in first textbox only and it will fill the second textbox . since second textbox have value now so it should validate the form.
Im not getting ....
This the complete code just copy paste you will get to know whats the problem.
Fill only first textbox.
- <!DOCTYPE html>
- <html>
- <head>
- <meta charset="utf-8" />
- <title>AngularJS Validation</title>
- <link rel="stylesheet" href="https://maxcdn.bootstrapcdn.com/bootstrap/3.4.0/css/bootstrap.min.css">
- <script src="https://ajax.googleapis.com/ajax/libs/jquery/3.3.1/jquery.min.js"></script>
- <script src="https://maxcdn.bootstrapcdn.com/bootstrap/3.4.0/js/bootstrap.min.js"></script>
- <script src="https://ajax.googleapis.com/ajax/libs/angularjs/1.6.9/angular.min.js"></script>
- <script>
-
- var validationApp = angular.module('validationApp', []);
-
- validationApp.controller('mainController', function ($scope) {
- });
- function sync() {
- var n1 = document.getElementById('txtname1');
- var n2 = document.getElementById('txtname2');
- n2.value = n1.value;
- }
- </script>
- </head>
- <body>
- <div ng-app="validationApp" ng-controller="mainController">
- <div class="container">
- <div class="row">
- <div class="col-sm-6">
- <!-- FORM ============ -->
- <form name="userForm" ng-submit="submitForm()" novalidate>
- <label>Enter name</label>
- <input type="text" name="name1" id="txtname1" ng-model="user.name1" class="form-control" onkeyup="sync()" required>
- <br />
- <!-- NAME -->
- <div class="form-group" ng-class="{ 'has-error' : userForm.name2.$invalid && !userForm.name2.$pristine,'has-success' : userForm.name2.$valid && !userForm.name2.$pristine }">
- <label>Name will be copy from the first textbox</label>
- <input type="text" name="name2" class="form-control" ng-model="user.name2" required id="txtname2">
- <p ng-show="userForm.name2.$invalid && !userForm.name2.$pristine" class="help-block">You name is required.</p>
- </div>
- <button type="submit" class="btn btn-primary" ng-disabled="userForm.$invalid">Submit</button>
- </form>
- </div>
- </div>
- <p>If we enter value in the first textbox then that value will be copy in the second textbox.<br/>That time form shuould valid and button should enable as well as in the second textbox green broder should come.(Angularjs Validation)</p>
- </div>
- </div>
- </body>
- </html>
If you have any solution please let me know....
Thank you