I have one textbox and one button and on button I have written below code. problem is suppose first I have entered in textbox 10 than its worked but when another time I enter 10 than also it prints value is not in array. so pls help me whats the issue...
jQuery(document).ready(function() { jQuery("#mybutton").live('click',function () { var sel_fam_rel=jQuery("#my_textbox").val(); var ids = []; code =sel_fam_rel; if($.inArray(code,ids) >= 0) { alert("Value is in array"); } else { alert("Value is not in array"); ids.push(code); } }); });
ids, So it will always go to else section. Show us your compete JS code.if($.inArray(code,ids) != -1)isn't this would be there?