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 es an ajax call
//[...]
}
}
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 es an ajax call
//[...]
}
}
Share
Improve this question
edited Feb 9, 2012 at 9:16
gdoron
150k59 gold badges302 silver badges371 bronze badges
asked Feb 9, 2012 at 8:15
LukeLuke
5,98113 gold badges58 silver badges77 bronze badges
2
- make sure that it is not null – Diode Commented Feb 9, 2012 at 8:21
- @Luke. What version? Try the code in Chrome or FF. – gdoron Commented Feb 9, 2012 at 9:16
1 Answer
Reset to default 2If the selector didn't find any element the val
function will return undefined
Try this:
if (kundeBoxVal) {
var adr_id = kundeBoxVal.split(';')[1];
}