0

I would like to replace the null record with N/A when possible in JavaScript.

I have the form, where some of the questions are reliant on other questions. If, for instance, some of the questions in marked as "yes" then other questions are not required, therefore they're inactive, as per below.

enter image description here

Next, I've prepared the email form like shown here:

HTML Assigning the checkbox to the form action already defined

and everywhere, where I have the unanswered question (while inactive ones) the result shows null.

I would like to have N/A instead of null everywhere, where questions are to be inactive due to selection.

My initial code looks like this:

   var surveyFailure = formData.get('h3g_survey_failure_reason');

and I tried something like this:

var surveyFailure = if 
 formData.get('h3g_survey_failure_reason') = null {
  surveyFailure = "N/A"
 };

but it doesn't work, as i get

Uncaught SyntaxError: Unexpected token 'if'

Is there any chance to replace the null with N/A?

Full code is available here:

https://jsfiddle.net/r5kw4f6g/

Geographos
  • 827
  • 2
  • 23
  • 57

1 Answers1

1

You have a syntax error, the correct code shoud be this:

var data = formData.get('h3g_survey_failure_reason');

var surveyFailure = (data === null) ? "N/A" : data;
Invictus
  • 426
  • 3
  • 13