I was trying to replace the null value that I get through a JSON after submitting a form by a String value like 'n/a' or 'not specified'. I have added few lines as @Winter Solider suggested which is commented below to check null value and replace it but the code I added doesn't work. And idea?
-thanks
function submitFormFunction() {
//document.getElementById("form").submit();
var valueArray = [
{
'label': 'contractId',
'value': document.getElementById('ContractId').value
},
{
'label': 'title',
'value': document.getElementById('ContractTitle').value
},
{
'label': 'minYear',
'value': document.getElementById('MinYear').value
},
{
'label': 'maxYear',
'value': document.getElementById('MaxYear').value
},
{
'label': 'terminal',
'value': document.getElementById('Terminal').value
},
{
'label': 'location',
'value': document.getElementById('Location').value
},
{
'label': 'theme',
'value': document.getElementById('Theme').value
},
{
'label': 'construction',
'value': document.getElementById('Construction').value
},
{
'label': 'asBuilt',
'value': document.getElementById('AsBuilt').value
}
].map(function (param) { return param.label + '=' + param.value; });
if (valueArray.length) {
// here I am trying to handle the null value issue as suggested by Winter Soldier
for (var i = 0; i < valueArray.length; i++) {
if (valueArray[i].includes("null")) {
valueArray[i] = valueArray[i].replace("null", "n/a");
}
}
console.log(valueArray)
console.log(valueArray.join('&'));
//var queryStr = JSON.stringify(valueArray.replacer);
var queryString = valueArray.join('&');
fetch(searchUrl, '?' + queryString, function (data) {
// output search results to the dom
renderSearchResults(JSON.parse(data), document.getElementById('searchResults'));
});
} else {
document.getElementById('searchResults').innerHTML = "Please enter a search term.";
}
}