Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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
      //[...]
    }
}
like image 535
Luke Avatar asked Apr 24 '26 12:04

Luke


1 Answers

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

if (kundeBoxVal) {
     var adr_id = kundeBoxVal.split(';')[1];
 }
like image 176
gdoron is supporting Monica Avatar answered Apr 26 '26 02:04

gdoron is supporting Monica