I have a question.
How to print/display in console all inputs values, selected options, checked checkbox & radio from form on submit?
searched on stackoverflow but couldn’t find a solution.
I have a question.
How to print/display in console all inputs values, selected options, checked checkbox & radio from form on submit?
searched on stackoverflow but couldn’t find a solution.
2
Answers
You can do it like this:
This will "detect" all
:input
elements and will write out different information based on the type,name and valueDemo
Assuming you’re submitting the form via AJAX, and that your form is not causing the page to reload, one way of doing it (apart from what @CarstenLøvboAndersen suggests) could be:
where
<your_form_identifier>
is the way you… Well, identify the form (ID, class, some other selector).If you don’t care about the actual type of the element, and you don’t want that shown in the console, this suggestion will log:
$(this).serialize()
– a string, in the form ofname=value&name2=value2...
for all of the form elements which are submitted (checked checkboxes, checked radiobuttons, etc)$(this).serializeArray()
– similar as the first, but as an array, instead of a stringIf you’re not using AJAX to submit your form, and are in fact reloading the page, then this suggestion (and the one by @CarstenLøvboAndersen) won’t enable you to see what is being submitted, unless you interrupt the submission with something like
e.preventDefault()
.