3

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
      //[...]
    }
}
2
  • make sure that it is not null Commented Feb 9, 2012 at 8:21
  • @Luke. What version? Try the code in Chrome or FF. Commented Feb 9, 2012 at 9:16

1 Answer 1

2

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

if (kundeBoxVal) {
     var adr_id = kundeBoxVal.split(';')[1];
 }
Sign up to request clarification or add additional context in comments.

2 Comments

He is checking kundeBoxVal != null and since null == undefined that should cover this case.
ok. the value was undefined. Now I need to find out why. But that's another story.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.