submitButton.onclick = function()

in src/client.js [67:105]


  submitButton.onclick = function(e) {
    
    // we do not collect the data, we just do the math client-side,
    // so we call preventDefault so that the data isn't sent anywhere and
    // the page isn't refreshed
    e.preventDefault();
    
    // get the form values
    const weeks = document.getElementById('weeks').value;
    const hours = document.getElementById('hours').value;
    const state = document.getElementById('state').value;
    
    // validate to make sure all the info was added to the form
    if (!weeks || !hours || !state) {
      validation.innerHTML = '<p class="error">You must enter all fields'
    }
    else {
      // if valid, we remove any existing warnings from past failure
      validation.innerHTML = '';
      
      // get the wage object for our state
      const stateObject = wages.filter(wage => wage.abbreviation === state)[0];
      if ( !stateObject ) {
        validation.innerHTML = '<p class="error">There seems to be no info for that state! Contact jenn@dotbiz.info for help!</p>';
        return;
      }
      
      // calculate the wage
      const wageString = ( stateObject.wage ) ? stateObject.wage.toFixed(2) : 'not required, so we will assume the federal minimum';
      stateObject.wage = ( stateObject.wage ) ? stateObject.wage : federalWage;
      
      const minimumWage = stateObject.wage * hours * weeks;
      
      const resultsString = `The federal minimum wage is <span class="federal">$${federalWage.toFixed(2)}</span>, ` + 
                              `but the minimum wage in <span class="state">${stateObject.name}</span> is <span class="wage">$${wageString}</span>.` +
                              `<p>Your minimum wage salary for the year (before taxes or overtime) would be <span class="total">$${minimumWage.toFixed(2)}</span></p>`; 
      results.innerHTML = resultsString;
    }
  }