-
Notifications
You must be signed in to change notification settings - Fork 0
objectifyForm
Mike Byrne edited this page Jan 25, 2022
·
4 revisions
Generates a JS Object out of a form. Note: does not add items from input[type=file]
or input[disabled]
.
You may also consider using FormData noting IE11 and Safari 10 can only make FormData and not interrogate or update the data.
- nothing
- form - required - form node
- JS Object compiled from the form
<form id='form'>
<label for='name'>Name</label>
<input type='text' id='name' name='name' value='Mike'>
<label for='description'>Description</label>
<textarea id='description' name='description'>Interface Engineer</textarea>
<label><input type='radio' name='role' value='FE' checked> FE</label>
<label><input type='radio' name='role' value='BE'> BE</label>
<label><input type='checkbox' name='staff' value='staff' checked> Staff</label>
</form>
var form = document.getElementsById('form');
var form_data = objectifyForm(form);
// Object {name: 'Mike', description: 'Interface Engineer', role: 'FE', staff: 'staff'}