Wednesday, February 13, 2013

How to Remove Array Values Using Javascript

How to Remove Added Values in Javascript

Method 1

 
function removeMilesCode(milesId) {
$("#milescode" + milesId).html("");
var list = document.getElementById('HdnAirlineCodeCheckExists').value.split('|');
var newInvList = '';
   if (list.length > 0) {
       for (var count = 0; count < list.length; count++) {
           if (list[count].split('~')[0] != '') {
               if (list[count].split('~')[0] != milesId) {
                    newInvList += list[count] + '|';
                  }
              }
          }
   }

document.getElementById('HdnAirlineCodeCheckExists').value = newInvList;

}


Method 2

var hidValue = document.getElementById('HdnAddTraveller').value;
var list = hidValue.split('^');
var newInvList = '';
if (list.length > 0) {
for (var count = 0; count < list.length; count++) {
var invesList = list[count].split('~');
                if (invesList[0] != '') {
                 var lista1 = customerValues[1] + '-' + customerValues[2];
                    var listb1 = invesList[0];
                        if (lista1 != listb1) {
                            newInvList += list[count] + '^';
                           }
                     }
              }
         }
   
if (newInvList != '') {
document.getElementById('HdnAddTraveller').value = newInvList;
}

No comments:

Post a Comment