Luke
Luke

Reputation: 5971

Split causes "Object doesn't support this property or method" exception

call to split on a variable causes a "Object doesn't support this property or method" exception and I don't know why. Here's my code:

function getKontaktPersonen(kontaktSelectBox) {
   var kontaktPersonen = [];
   var id_and_name = kontaktSelectBox.attr('id');
   var id_part = getID_PartFromName(id_and_name);
   var textboxname;
   var selectboxname;
   if (kontaktSelectBox.attr('class') == 'kontaktSelectBox') {

        textboxname = "TextBoxKunde" + id_part;
        selectboxname = "SelectBoxKontaktPerson" + id_part;
    } else if (kontaktSelectBox.attr('class') == 'NewkontaktSelectBox') {
        textboxname = "NewTextBoxKunde" + id_part;
        selectboxname = "NewSelectBoxKontaktPerson" + id_part;
    } else {
        return false;
    }
    var kundeBox = $('#' + textboxname);
    var kundeBoxVal = kundeBox.val();
    if (kundeBoxVal != '' && kundeBoxVal != null) {
     var adr_id = kundeBoxVal.split(';')[1];
      //here comes an ajax call
      //[...]
    }
}

Upvotes: 3

Views: 13691

Answers (1)

gdoron
gdoron

Reputation: 150313

If the selector didn't find any element the val function will return undefined Try this:

if (kundeBoxVal) {
     var adr_id = kundeBoxVal.split(';')[1];
 }

Upvotes: 2

Related Questions