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/

1 Answer 1

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;

Sign up to request clarification or add additional context in comments.

Comments

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.