error with javascript globals and jquery call back functions -


i'm trying make array of value's checked see if value has been added before.

if has show alert. if hasn't added array , conduct post ajax query server retrieve corresponding table row.

i'm novice when comes javascript , i'm finding hard debug because fault in syntax breaks entire script.

here code if see's error u tell me how fix it.

also if know program debugging java-script helpful.

i know jquery calls work fine because added in array check afterwards.

var selectedproductsarray = new array(); var selectedproductscount = 0;  $(function() {     $('.selectproductid').live('click', function(event) {          var count = 0;         var found = false;         while(count < selectedproductscount)         {             if(selectedproductsarray[count] == $(this).val())             {                 found = true;                 break;             }             count++;         }          if(found)         {             alert("you can add 1 line each product.");         }else{             selectedproductsarray[selectedproductscount] = $(this).val();             selectedproductscount++;             $.post("order/getitem", "productid="+$(this).val(), function(data){                 $("#orderitems tbody").append(data);                 selectedproductscount++;             });         }         return false;     }); }); 

firstly, there no "array" class i'm surprised getting passed that; want:

var selectedproductsarray = new array(); 

or

var selectedproductsarray = [ ]; 

also, don't need keep computing $(this).val() on , on again, should say:

var count = 0; var found = false; var value = $(this).val(); 

above while loop , reference value instead of $(this).val() in rest. you're incrementing selectedproductscount twice when think want once, leave empty/null entries in selectedproductsarray , might confuse things later on.

i can't eye-ball other glaring errors new array() 1 should show stopper. hard without functioning example.

does order/getitem called? send back?

for debugging , trying things out:


Comments

Popular posts from this blog

asp.net - repeatedly call AddImageUrl(url) to assemble pdf document -

java - Android recognize cell phone with keyboard or not? -

iphone - How would you achieve a LED Scrolling effect? -