onaled777
asked on
TypeError: Cannot read property "length" of undefined.
I keep getting the error: TypeError: Cannot read property "length" of undefined.
It seems to happen at the line searchparams: JSON.stringify(jsonObj)
Can anyone help me find out why?
It seems to happen at the line searchparams: JSON.stringify(jsonObj)
Can anyone help me find out why?
function runAdvancedSearch() {
disableAdvancedSearch()
var resultsDiv = document.getElementById('searchResutsDiv');
var jsonObj = new Object();
if ($('#inpAdvSearchCaseId').val().length>0) {
jsonObj.caseId = $('#inpAdvSearchCaseId').val();
}
if ($('#inpAdvSearchCaseNo').val().length>0) {
jsonObj.caseNo = $('#inpAdvSearchCaseNo').val();
}
if ($('#inpAdvSearchCitationNo').val().length>0) {
jsonObj.citationNo = $('#inpAdvSearchCitationNo').val();
}
var dtVal = null;
if ($('#dtAdvSearchFiledFrom').val().length>0) {
dtVal = toDateFrom_mmddyyyy($('#dtAdvSearchFiledFrom').val());
if (isDate(dtVal)) {
jsonObj.filedBetweenStart = dtVal.getTime();
}
}
if ($('#dtAdvSearchFiledTo').val().length>0) {
dtVal = toDateFrom_mmddyyyy($('#dtAdvSearchFiledTo').val());
if (isDate(dtVal)) {
jsonObj.filedBetweenEnd = dtVal.getTime();
}
}
if ($('#inpAdvSearchCaseLegacyId').val().length>0) {
jsonObj.legacyId = $('#inpAdvSearchCaseLegacyId').val();
}
if ($('#inpAdvSearchArrestNo').val().length>0) {
jsonObj.arrestNo = $('#inpAdvSearchArrestNo').val();
}
if ($('#inpAdvSearchPartyLastName').val().length>0) {
jsonObj.partyLastName = $('#inpAdvSearchPartyLastName').val();
}
if ($('#inpAdvSearchPartyFirstName').val().length>0) {
jsonObj.partyFirstName = $('#inpAdvSearchPartyFirstName').val();
}
if ($('#inpAdvSearchPartyMiddleName').val().length>0) {
jsonObj.partyMiddleName = $('#inpAdvSearchPartyMiddleName').val();
}
if ($('#dtAdvSearchPartyDOB').val().length>0) {
dtVal = toDateFrom_mmddyyyy($('#dtAdvSearchPartyDOB').val());
if (isDate(dtVal)) {
jsonObj.partyDateOfBirth = dtVal.getTime();
}
}
if ($('#inpAdvSearchDriversLicense').val().length>0) {
jsonObj.driversLicense = $('#inpAdvSearchDriversLicense').val();
}
if ($('#inpAdvSearchSSN').val().length>0) {
jsonObj.ssNo = $('#inpAdvSearchSSN').val();
}
if ($('#inpAdvSearchBookingNo').val().length>0) {
jsonObj.bookingNo = $('#inpAdvSearchBookingNo').val();
}
if ($('#attyLastName').val().length>0) {
jsonObj.attyLastName = $('#attyLastName').val();
}
if ($('#attyFirstName').val().length>0) {
jsonObj.attyFirstName = $('#attyFirstName').val();
}
if ($('#attyMiddleName').val().length>0) {
jsonObj.attyMiddleName = $('#attyMiddleName').val();
}
if ($('#barNo').val().length>0) {
jsonObj.barNo = $('#barNo').val();
}
if ($('#judicialOfficer').val().length>0) {
jsonObj.judicialOfficer = $('#judicialOfficer').val();
}
if ($('#magistrate').val().length>0) {
jsonObj.magistrate = $('#magistrate').val();
}
$.ajax({
url: '/ebench/search/run',
type: 'POST',
data : {
searchparams: JSON.stringify(jsonObj)
},
dataType: 'json',
success: function(data, status, request) {
switch (request.status) {
case 200: break;
case 299: logout(); return;
default:
errorFunction(request);
showEmptyAdvancedSearchResults(resultsDiv);
enableAdvancedSearch()
return;
}
try {
resultsDiv.innerHTML = '';
if (!data || data===null) {
showEmptyAdvancedSearchResults(resultsDiv);
enableAdvancedSearch()
return;
}
var list = jQuery.extend(true, [], data);
if (list===null || list.length<1) {
showEmptyAdvancedSearchResults(resultsDiv);
enableAdvancedSearch()
return;
}
var elem = document.createElement('div');
resultsDiv.appendChild(elem);
var el = document.createElement('span');
elem.appendChild(el);
el.className = 'bigBoldText';
el.textContent = 'Total cases found: '+list.length;
var i=0;
var divCode = null;
var filedOn = null;
var caseStatus = null;
var style = null;
for (i=0; i<list.length; i++) {
divCode = list[i].divCode;
if (divCode===null || divCode.length<1)
divCode = 'N/A';
filedOn = list[i].filedOn;
if (filedOn===null || filedOn.length<1)
filedOn = 'N/A';
else
filedOn = toStrDate_mmddyyyy(new Date(filedOn));
caseStatus = list[i].status;
if (caseStatus===null || caseStatus.length<1)
caseStatus = 'N/A';
style = list[i].style;
if (style===null || style.length<1)
style = 'N/A';
/*else
style = encodeHtml(style);*/
elem = document.createElement('div');
resultsDiv.appendChild(elem);
elem.className = 'row-fluid caseInfoHeader pointer backgroundColorNavyBlue';
elem.textContent = list[i].caseNo+' '+divCode+' '+filedOn+' '+caseStatus;
elem.onclick = getCaseFileScopePreserver(list[i].caseId);
elem = document.createElement('div');
resultsDiv.appendChild(elem);
elem.className = 'pointer marginBottom10';
elem.onclick = getCaseFileScopePreserver(list[i].caseId);
el = document.createElement('span');
elem.appendChild(el);
el.className = 'docketStyle';
el.textContent = style;
}
} catch (e) {
errorFunction(e);
showEmptyAdvancedSearchResults(resultsDiv);
enableAdvancedSearch()
return;
}
},
error: function(data, status, request) {
switch (data.status) {
case 200:
errorFunction(request);
showEmptyAdvancedSearchResults(resultsDiv);
enableAdvancedSearch();
return;
case 299: logout(); return;
default: errorFunction(data.statusText);
}
}
});
}
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
ASKER
Thanks for your input all. Yes I am in the process of getting more familiar with the debugging tools and was able to find the error the second time around.
B-) Glad we could help. Thx for the grade and points
Maybe you meant $('#inpAdvSearchCaseId').v
Something more robust would probably be
if (typeof $('#inpAdvSearchCaseId').v