HTML JAVASCRIPT

HOW TO GET HTML FORM DATA IN JAVASCRIPT

    <option>Divorced/Widowed</option>   </select>     <input type="submit" value="Go!"/> </form>

HTML FORM

01

<form id="form" onsubmit="return doForm()">   <input type="text" id="name"    name="name" required value="Jon"/>     <select id="marital" name="marital">     <option>Single</option>     <option>Married</option>

function doForm() {   EASY WAY - AUTO GET ALL FIELDS   var data = new FormData(document.   getElementById("form"));     MANUALLY APPEND FIELD   data.append("name", document.   getElementById("name"));

JAVASCRIPT GET FORM DATA

02

  GET MULTIPLE FIELDS AT ONCE    var all = document.querySelectorAll   ("#form input, #form select");   for (let field of all)    { data.append(field.name, field.value); }   }