Jump to content

Undefined problem


robert_gsfame

Recommended Posts

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

Link to comment
https://forums.phpfreaks.com/topic/196071-undefined-problem/
Share on other sites

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.