sknagesh Posted January 17, 2012 Share Posted January 17, 2012 Hi Here is the code. $('#add').click(function(){ var drawingid=$('#Drawing').val(); var incommingid=$('#Challan_ID').val(); var qty=$('#qty').val(); var Max_Qty=0; var url='get_challan_qty.php?drawingid='+drawingid+'&incommingid='+incommingid+'&qty='+qty; $.get(url, function(result) { Max_Qty=result; console.log(Max_Qty); }); console.log(Max_Qty); if(drawingid==''||incommingid==''||qty=='') { alert("Please select Corect Drawing, Challan No and Quantity"); return false; }else if (Max_Qty<qty) { alert("Please enter correct Quantity"); } elae { var url='get_comp_challan_details.php?drawingid='+drawingid+'&incommingid='+incommingid+'&qty='+qty; $.get(url, function(result) { data[noofcomp]=result.split("<|>") var newtr="<tr><td>"+data[noofcomp][0]+"</td><td>"+data[noofcomp][1]+"</td><td>"+data[noofcomp][2]+"</td><td>"+data[noofcomp][3]+"</td><td>"+data[noofcomp][4]+"</td><td>"+data[noofcomp][5]+"</td><td>"+data[noofcomp][6]+"</td><td>"+data[noofcomp][7]+"</td></tr>"; $('#added').show(); $('#added').append(newtr); $('#data').val(data); $('#noofcomp').val(noofcomp); noofcomp++; }); } Max_Qty inside the .get() function prints the expected value. But once it is outside the function its value is 0. Why is this?. TIA SKN Link to comment https://forums.phpfreaks.com/topic/255219-what-is-wrong-withis-code/ Share on other sites More sharing options...
spiderwell Posted January 24, 2012 Share Posted January 24, 2012 maybe its only scope is inside the function so it wont have a value outside of it? Link to comment https://forums.phpfreaks.com/topic/255219-what-is-wrong-withis-code/#findComment-1310658 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.