Click here to Skip to main content
15,908,175 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
i have a textbox and a button inside a div and that div is created dynamically

What I have tried:

.js file
--------------------------------

html file
---------------------------------------------


Posted
Updated 15-May-16 19:34pm
v4

1 solution

try this

JavaScript
$scope.addcrt = function (quantity) {
               // alert (quantity);
               $scope.arr.push({ "item": $scope.itid, "prc": $scope.amt, "qtt": quantity });

           }



HTML
<input type='text' id='txtqty' ng-model="qt" />
                <input type='button' ng-click="addcrt(qt)" class='btnadd' value='Add' />
 
Share this answer
 
Comments
Karthik_Mahalingam 13-May-16 11:07am    
try this

<input type='button' ng-click="addcrt(qt,it)" class='btnadd' value='Add' />

$scope.addcrt = function (quantity,it) {
// alert (quantity);
alert(it.price1)
alert(it.item_id)


let me know if it works
Karthik_Mahalingam 13-May-16 11:13am    
post your full code, i thing you are missing some
Karthik_Mahalingam 13-May-16 11:35am    
try my code, and modify it as per your need.
Karthik_Mahalingam 13-May-16 11:33am    
try this in a new html page.

<!DOCTYPE html>
<html lang="en-US">
<head>
<script src="angular.js"></script>
<!--<script src="http://ajax.googleapis.com/ajax/libs/angularjs/1.4.8/angular.min.js"></script>-->
<script>
var app = angular.module('myapp', []);
app.controller('myctrl', myctrl);

function myctrl($scope, $http, $timeout, $interval) {

$scope.z = [{ item_img: '', item_id: 1, item_name: 'apple', price1: 50, },
{ item_img: '', item_id: 2, item_name: 'orange', price1: 35, },
{ item_img: '', item_id: 3, item_name: 'lemo', price1: 10, }];

$scope.arr = [];


$scope.addcrt = function (quantity,it) {
$scope.arr.push({ "itemid": it.item_id, "itemname": it.item_name, "prc": it.price1, "qtt": quantity });
}
}

</script>



</head>
<body>

<div ng-app="myapp" ng-controller="myctrl as model">
<div ng-repeat="it in z">
<div>
<span ng-bind="it.item_name"></span>
<span ng-bind="it.price1"></span>
<input type='text' id='txtqty' ng-model="qt" />
<input type='button' ng-click="addcrt(qt,it)" class='btnadd' value='Add' />
</div>
</div>
<ul>
<li ng-repeat="it in arr">
Id: <span ng-bind="it.itemid"></span> <br />
Name: <span ng-bind="it.itemname"></span> <br />
Price:<span ng-bind="it.prc"></span><br />
Quantity:<span ng-bind="it.qtt"></span><br />
</li>
</ul>

</div>


</body>
</html>
Karthik_Mahalingam 13-May-16 11:58am    
So . what validation you need ?

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900