Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to send the input text box value to angularjs onclick on the text box?

Tags:

html

angularjs

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> 
like image 971
maho Avatar asked Feb 13 '14 10:02

maho


1 Answers

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)" />
like image 90
kubuntu Avatar answered Nov 15 '22 07:11

kubuntu