7

Below is my html:

<tr ng-repeat="c in client">
     <td><input type =text id = "id" value = {{c.id}} onclick = "display();" > </input> </td>
     <td><input type =text value = {{c.fname}}></td>
</tr>

My js:

 function display()
 {
     var x=document.forms["form"]["id"].value;
     alert(x);       
 }

I am getting the input value in the alert box successfully but how to get this value in another angular js function. I tried the below code but not working please suggest me

<input type =text id = "id" value = {{c.id}} ng-model = user.id ng-click ="init(user)" > </input> 
1
  • 2
    Where is your controller code? Commented Feb 13, 2014 at 10:40

2 Answers 2

4

If you have set up your application properly, you simply create the init() function in your controller

$scope.init = function (user) {
    // function implementation
};

Also make sure you format your HTML correctly

<input type="text" id="id" value="{{c.id}}" ng-model="user" ng-click ="init(user)" />
Sign up to request clarification or add additional context in comments.

5 Comments

is it possible to give ng-click in input text box?
<input type ="text" value = "sample" ng-model = "user" ng-click ="init(user)" /> I gave it like this its showing empty text box, why I am not getting the sample in text box
ng-model = "user" overrides value = "sample". You could set the value of user in HTML <input type="text" ng-model="user" ng-click="init(user)" ng-init="user='sample'" /> or in your controller. Also, depending on what you want to achieve, you may want to consider ng-change and ng-focus. A user could type into the text box without clicking.
thanks working for sample.one last doubt instead of sample I need to give a dynamic value from my collection object ie c.id (from this<tr ng-repeat="c in client">)
Make your ng-model the value you want there (i.e. ng-model="c.id").
-1

A much more cleaner way to accomplish the same thing would be to just set the value on the click event for example.

<td onclick="user.id=ID"> </td>

1 Comment

I think you mixed up angularjs with java script?

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.