Passing variables from a form to Dropzone using params

Viewed 14

I am using Dropzone and trying to pass values from a form as params. For text and a dropdown list this works perfectly.

<input type="text" name="lastname" id="lastname">
<select name="age" id="age">
   <option value="20">Year 20</option>
   <option value="30">Year 30</option>
   <option value="40">Year 40</option>
</select>

params: () => ({
  lastname: document.querySelector('#lastname').value,
  age: document.querySelector('#age').value,
}),

but I am struggling with how to do it with a checkbox.

 <input type="checkbox" id="apple" name="apple" value="Y"> Apple
 <input type="checkbox" id="orange" name="orange" value="Y"> Orange

params: () => ({
  lastname: document.querySelector('#lastname').value,
  age: document.querySelector('#age').value,
  apple: document.querySelector('#apple').value,
  orange: document.querySelector('#orange').value,
}),

This passed Y to Apple and Orange whether they were checked or not.

I then added hidden fields with the value of N

 <input type="hidden" id="apple" name="apple" value="N"> Apple
 <input type="checkbox" id="apple" name="apple" value="Y"> Apple
 <input type="hidden" id="orange" name="orange" value="N"> Orange
 <input type="checkbox" id="orange" name="orange" value="Y"> Orange

This passed the value of N whether the fields were checked or not.

I would like to be able to pass Y if the field is checked and either N or a blank if it is not.

0 Answers
Related