Click here to Skip to main content
15,887,471 members
Home / Discussions / JavaScript
   

JavaScript

 
QuestionHelp Needed Pin
Member 1231273311-Feb-16 10:43
Member 1231273311-Feb-16 10:43 
QuestionRe: Help Needed Pin
ZurdoDev23-Feb-16 9:02
professionalZurdoDev23-Feb-16 9:02 
QuestionJquery, changing span values with HTML5 data attr inside a div Pin
jkirkerx11-Feb-16 9:50
professionaljkirkerx11-Feb-16 9:50 
AnswerRe: Jquery, changing span values with HTML5 data attr inside a div Pin
Richard Deeming11-Feb-16 10:17
mveRichard Deeming11-Feb-16 10:17 
GeneralRe: Jquery, changing span values with HTML5 data attr inside a div Pin
jkirkerx11-Feb-16 10:54
professionaljkirkerx11-Feb-16 10:54 
GeneralRe: Jquery, changing span values with HTML5 data attr inside a div Pin
Nathan Minier12-Feb-16 1:55
professionalNathan Minier12-Feb-16 1:55 
GeneralRe: Jquery, changing span values with HTML5 data attr inside a div Pin
jkirkerx12-Feb-16 6:30
professionaljkirkerx12-Feb-16 6:30 
GeneralRe: Jquery, changing span values with HTML5 data attr inside a div Pin
Nathan Minier12-Feb-16 7:03
professionalNathan Minier12-Feb-16 7:03 
Well, general JavaScript and jQuery do not support any sort of data binding, so when data is modified for any reason you may miss it, or use JavaScript to walk the DOM until you locate the appropriate element.

Data binding frameworks eliminate this necessity. You can use them to bind a JavaScript variable to an element on the DOM. This means that when a value is updated either from an AJAX call or from user interaction, the change reflects in both the script and on the DOM.

For instance, I could rewrite your sample as:
HTML
<html ng-app="myApp">
...
<div ng-controller="myCartController">
<div class="cartRecord" ng-click="doSomething()">
   <div class="cartQty">
       <input type="text" ng-model="model.quantity" />
   </div>
   <div class="cartSKU">
       <span>{{model.SKU}}</span>   </div>
   <div class="cartDescription">
       <span>{{model.Description}}</span>
   </div>
   <div class="cartPrice">
       <span>{{model.price | currency : '$' : 2}}</span>
   </div>
   <div class="cartTotal">
       <span>{{model.total}}</span>
   </div>
</div>
</div>

<script type="text/javascript">
angular.module('myApp',[])
   .controller('myCartController',['$scope',function($scope){
      $scope.model = MethodToGetModelFromAJAX();

      $scope.model.total = $scope.model.price * $scope.model.quantity;

      $scope.doSomething = function(){
         // do something!
      }
   }
</script>
</html>

Never mind the Angular-specific syntax, that code will allow you to populate the HTML via AJAX, update the quantity and recalculate the total, format the currency, and will even "do something!" on click.
GeneralRe: Jquery, changing span values with HTML5 data attr inside a div Pin
jkirkerx12-Feb-16 8:17
professionaljkirkerx12-Feb-16 8:17 
GeneralRe: Jquery, changing span values with HTML5 data attr inside a div Pin
Nathan Minier12-Feb-16 8:34
professionalNathan Minier12-Feb-16 8:34 
SuggestionRe: Jquery, changing span values with HTML5 data attr inside a div Pin
Richard Deeming12-Feb-16 8:41
mveRichard Deeming12-Feb-16 8:41 
GeneralRe: Jquery, changing span values with HTML5 data attr inside a div Pin
Nathan Minier12-Feb-16 8:57
professionalNathan Minier12-Feb-16 8:57 
GeneralRe: Jquery, changing span values with HTML5 data attr inside a div Pin
jkirkerx12-Feb-16 9:13
professionaljkirkerx12-Feb-16 9:13 
QuestionJTable Add New Record button Pin
Member 1231770910-Feb-16 0:25
Member 1231770910-Feb-16 0:25 
Questionhow to open the JTable Add new Record form in button click in another form Pin
Member 123177099-Feb-16 23:02
Member 123177099-Feb-16 23:02 
AnswerMy Vote of 1 Pin
Keith Barrow12-Feb-16 4:57
professionalKeith Barrow12-Feb-16 4:57 
Questionworking with showCreateForm() in jtable Pin
Member 123177099-Feb-16 19:23
Member 123177099-Feb-16 19:23 
AnswerRe: working with showCreateForm() in jtable Pin
F-ES Sitecore9-Feb-16 22:42
professionalF-ES Sitecore9-Feb-16 22:42 
GeneralRe: working with showCreateForm() in jtable Pin
Member 123177099-Feb-16 22:55
Member 123177099-Feb-16 22:55 
GeneralRe: working with showCreateForm() in jtable Pin
F-ES Sitecore9-Feb-16 22:58
professionalF-ES Sitecore9-Feb-16 22:58 
QuestionWhen IFrame load event is called ? Pin
Tridip Bhattacharjee4-Feb-16 1:45
professionalTridip Bhattacharjee4-Feb-16 1:45 
AnswerRe: When IFrame load event is called ? Pin
F-ES Sitecore9-Feb-16 22:26
professionalF-ES Sitecore9-Feb-16 22:26 
GeneralRe: When IFrame load event is called ? Pin
Tridip Bhattacharjee10-Feb-16 2:09
professionalTridip Bhattacharjee10-Feb-16 2:09 
GeneralRe: When IFrame load event is called ? Pin
F-ES Sitecore10-Feb-16 2:16
professionalF-ES Sitecore10-Feb-16 2:16 
GeneralRe: When IFrame load event is called ? Pin
Tridip Bhattacharjee10-Feb-16 20:44
professionalTridip Bhattacharjee10-Feb-16 20:44 

General General    News News    Suggestion Suggestion    Question Question    Bug Bug    Answer Answer    Joke Joke    Praise Praise    Rant Rant    Admin Admin   

Use Ctrl+Left/Right to switch messages, Ctrl+Up/Down to switch threads, Ctrl+Shift+Left/Right to switch pages.