title: Saving user's text input and dropdown selections as items in an object with JavaScript/Jquery?
body: <p>I built a page for a user to generate a game character, and it lets them either randomize or input their own choices for each trait. I have the randomization all set up, and it saves those selections just fine, but I'm having trouble getting it to save the selections properly if the user chooses their own input instead.</p>
  <p>Basically, I have a series of toggle switches that check whether they want a trait randomized or not, and if not, they get to type their choice into a text box or choose an option from a select element dropdown menu (ie. each trait has either a dropdown menu OR a text input, but not both).</p>
  <p>For choosing their character name, if they want to write it themselves, I have an input element text box:</p>
  <pre><code>&lt;input placeholder=&quot;Type name&quot; id=&quot;nameUsed&quot; type=&quot;text&quot; class=&quot;validate&quot;&gt;
  </code></pre>
  <p>For choosing their other traits, I have select dropdown menus with multiple options like this one (there are three of these menus, one for each trait):</p>
  <pre><code>&lt;select id=&quot;alignMenu&quot; name=&quot;alignment&quot; class=&quot;text-dark&quot;&gt;
          &lt;option value=&quot;chaotic-neutral&quot;&gt;chaotic-neutral&lt;/option&gt;
          &lt;option value=&quot;chaotic-evil&quot;&gt;chaotic-evil&lt;/option&gt;
          &lt;option value=&quot;chaotic-good&quot;&gt;chaotic-good&lt;/option&gt;
          &lt;option value=&quot;lawful-neutral&quot;&gt;lawful-neutral&lt;/option&gt;
          &lt;option value=&quot;lawful-evil&quot;&gt;lawful-evil&lt;/option&gt;
          &lt;option value=&quot;lawful-good&quot;&gt;lawful-good&lt;/option&gt;
          &lt;option value=&quot;neutral&quot;&gt;neutral&lt;/option&gt;
          &lt;option value=&quot;neutral-evil&quot;&gt;neutral-evil&lt;/option&gt;
          &lt;option value=&quot;neutral-good&quot;&gt;neutral-good&lt;/option&gt;
  &lt;/select&gt;
  </code></pre>
  <p>They click this button to save their input:</p>
  <pre><code>&lt;button class=&quot;btn waves-effect waves-light red darken-4&quot; type=&quot;submit&quot; name=&quot;saving&quot; id=&quot;lockIn&quot;&gt;Save Choices&lt;/button&gt;
  </code></pre>
  <p>I have the traits saved as items in an object called CharacterAttributes, and this is the content of the JavaScript function I currently have to try to save those items when the Save button is clicked:</p>
  <pre><code>if ($('#name-choice').is(&quot;:checked&quot;)) {
    }
    else {
      CharacterAttributes.name = JSON.stringify($('#nameUsed').val);
    };
  
  if ($('#align-choice').is(&quot;:checked&quot;)) {
    }
    else {
      CharacterAttributes.alignment = JSON.stringify($('#alignMenu').val);
    };
  </code></pre>
  <p>Name-choice and align-choice are the ID's of the toggle switches, so it's checking if the user wants it randomized or not. If it is randomized, it won't do anything since another function takes care of that, but if the user made their own selection, I want it to save the text typed into the nameUsed input field, and to save the dropdown option currently selected in the alignMenu.</p>
  <p>As it is right now, those values are saving as 'undefined.' Can anyone help me figure out what I'm doing wrong here?</p>