Don't like ads? PRO users don't see any ads ;-)
Guest

Untitled

By: a guest on Aug 11th, 2012  |  syntax: None  |  size: 1.53 KB  |  hits: 8  |  expires: Never
download  |  raw  |  embed  |  report abuse  |  print
Text below is selected. Please press Ctrl+C to copy to your clipboard. (⌘+C on Mac)
  1. Value returning undefined if used in function
  2. <div class="one" data-selection="1"></div>
  3. <p class="selections"></p>
  4. <p class="cost">£ <span class="price">0</span></p>
  5.        
  6. <script>
  7. // Empty array to capture selections
  8.     var a = [];
  9.     var originalValue = "You have Selected section(s): ";  
  10.     $(".one").click(function () {
  11.         if ($(this).attr('class') == "selected one") {  
  12.             //alert
  13.             alert("Are you sure you wish to de-select?");      
  14.             //remove from the total
  15.             $(".price").html(parseInt($(".price").html(),10) - 30)  
  16.             $(this).removeClass("selected ");  
  17.             // need to get remove from array
  18.             var removeItem = $(this).attr("data-selection");  
  19.             a = jQuery.grep(a, function(value) {
  20.                 return value != removeItem;
  21.             });      
  22.             $('.selections').text(originalValue + a);  
  23.         }
  24.         else {
  25.             var selection = $(this).attr("data-selection");
  26.             alert(selection);
  27.             var originalSrc = $(this).attr('class');
  28.             $(this).attr('class', 'selected ' + originalSrc);    
  29.             a.push(1);
  30.             a.sort();          
  31.             $('.selections').text(originalValue + a);  
  32.             $('.price').text(function(i, txt) {
  33.                 return +txt + 30;
  34.             });
  35.         }
  36.     });
  37. </script>
  38.        
  39. undoSelection()
  40.        
  41. $(".one").click(function () {
  42.     if ($(this).attr('class') == "selected one") {
  43.         undoSelection();
  44.     }
  45.     else {
  46.        
  47. $(this).attr("data-selection");