javascript - jQuery.inArray returns always -1 -


i have following shoping list

enter image description here

and want each time user click on trash can product deleted list. have this:

  $(document).ready(function() {  var selectedproducts = new array(); //list of selected products    $("#add_product_button").button(); $("#add_product_button").click(function() {     //add products selectedproducts       //omitted clarity selectedproducts[i]=document.getelementbyid("autocomplete_text_field").value;          thesi=jquery.inarray(document.getelementbyid("autocomplete_text_field").value,selectedproducts);            var row=$('<div class"productsclass" style="height:50px; background-color:#e36d84; -webkit-border-radius: 5px; border-radius: 5px; border-style:solid; border-color:#db4865; id='+rowid+'" ><label style="position:relative; top:10px; left:2px; font-size:20px">'+selectedproducts[i]+'</label><input  style="position:relative; left:2px; top:10px; width:20px;" type="text" name="quantity" value="1"><img class="delete" id="'+rowid+'" src="http://b.dryicons.com/images/icon_sets/handy_part_2_icons/png/128x128/recycle_bin.png" height="22"  width="22" style="position:relative; top:10px; float: right;"></div><br>');         rowid++;        $("#productstable").append(row);        i++;        console.log("thesi: "+thesi+" timi:"+document.getelementbyid(thesi).value);  });     //delete products $(document).on("click", "[class*='delete']", function(s) {      thisid = $(this).attr('id'); //find items parent     console.log("thisid: "+thisid);     console.log(jquery.inarray(thisid,selectedproducts));//find item's position in selectedproducts     selectedproducts.splice(thisid,1);     $(this).parent().hide("explode", 1000);     $(this).parent().remove();//delete item     console.log("size:"+selectedproducts.length);     console.log(selectedproducts);   });    }); 

the problem jquery.inarray returns -1. correct product deleted ui selectedproducts array

html:

  <div id="maindiv" class="maindiv"> <input id="autocomplete_text_field"> <button id="add_product_button">add product</button> </div>  <div id="supplier"> <form name="frm1" action="http://localhost/tddd27/index.php/auth/session"> <input type="image" src="<?php echo base_url()?>assets/images/fb_supplier.png" /> </form> </div>   <div id="productsdiv" class="productsdiv" hidden="true"> <div id="tabs">   <ul>     <li><a href="#fragment-1"><span>shopping list</span></a></li>   </ul>   <div id="fragment-1">  <form action="#" id="productstable" name="productstable"> <p></p> </form> </div>   </div> </div> 

any idea problem?

your asking for

thesi=jquery.inarray(thisid,selectedproducts); 

but

selectedproducts 

is not defined. or missing something?


Comments

Popular posts from this blog

linux - Does gcc have any options to add version info in ELF binary file? -

android - send complex objects as post php java -

charts - What graph/dashboard product is facebook using in Dashboard: PUE & WUE -