robert_gsfame Posted March 22, 2010 Share Posted March 22, 2010 Again another problem with an array without value. I have this code: All array will automatically created from 1 to 100 even if no value in it. Yet i use "undefined" to check the array and wish to replace the "undefined" with "nodata" ....i have tried but still the code not working :'( function check() { var a=0; var myarray=new Array(); for(i=1;i<100;i++){ if(document.getElementById(i)!==null){ if(document.getElementById(i).checked==true){ myarray[a]=i; a++; } } } if(a>0){ var okay= confirm("are you sure to erase all?"); if (okay== true){ if(myarray[0]!=="undefined"){ var data1=myarray[0]+",";}else{ var data1="nodata";} if(myarray[1]!=="undefined"){ var data2=myarray[1]+",";}else{ var data2="nodata";} var combine=data1+data2; var combine2=combine.substring(0,combine.length-1); } alert('combine2'); } thanks for your helps Quote Link to comment https://forums.phpfreaks.com/topic/196071-undefined-problem/ Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.