0

I've 3 input fields the first field is of type select and the remaining two are of type text. Now if I select a value from dropdown list, then the corresponding values should appear in the remaining two input fields. How to do it in AngularJS. Thank you!

For example if I select User1 from the dropdown then User1 corresponding email & phone number should appear in the corresponding input fields.

NOTE: the values are fetched from the database based on the selected option

<select>
    <option value="user1">User1</option>
    <option value="user2">User2</option>
    <option value="user3">User3</option>
    <option value="user4">User4</option>
</select>
<input type="text" id="eamil" placeholder="Email">
<input type="text" id="phone_no" placeholder="Phone number">
4
  • Show us your code man ? Commented Sep 30, 2016 at 12:59
  • I don't have any idea on how to achieve this, so please let me know the way Commented Sep 30, 2016 at 13:00
  • Can you show us your full code till now ? Commented Sep 30, 2016 at 13:01
  • @Loading.. it is just a task, not a part of project. Commented Sep 30, 2016 at 13:03

3 Answers 3

2
<select ng-options="s as s in Users" ng-model="user" ng-change = "GetData(user)">

<input type="text" id="eamil" placeholder="Email" ng-model="userEmail">

<input type="text" id="phone_no" placeholder="Phone number" ng-model="userPhone">

Now on controller

$scope.GetData = function(user){
  // Here Please add Code to fetch the data from database. Here userEmailFromDB and userPhoneFromDB are the values that you get from database. 

   $scope.userEmail = userEmailFromDB; 
   $scope.userPhone = userPhoneFromDB;
}
Sign up to request clarification or add additional context in comments.

6 Comments

I'm using MySQL ang PHP for the backend. How can I fetch the values and assign them to $scope.userEmail & $scope.userPhone?
Have you written any SQL queries to get data based on the user?
Yes I've written the query in php file
Can i see the code from the php file? What is the function name , what parameters does it take and what does it return.
I got it, I use http.get to fetch the results from my database. Thanks man.
|
1
$scope.userListSelected = function(userList){ $scope.email = userList.email; $scope.phoneNumber = userList.phoneNumber;

<select ng-model="userList" ng-options="user.name for user in userData" ng-change="userListSelected(userList)">

<input type=text ng-model="email" />
<input type=text ng-model="phoneNumber"/>

Comments

0

I have something like this, may it helps:

$scope.onChangeSelectedUser = function(item) {
  $scope.user.user_id = item.id;
}
    
$scope.selectedUser = [];    
<select class="form-control with-search" select-picker data-live-search="true" title="Select User" ng-model="selectedUser"
ng-options="u as u.email for u in users"
ng-change="onChangeSelectedUser(selectedUser)">
</select>

<input type="text" readonly class="form-control" ng-model="selectedUser.user_id"/>        
<input type="text" readonly class="form-control" ng-model="selectedUser.email"/>
<input type="text" readonly class="form-control" ng-model="selectedUser.phone_no"/>

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.