Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

how can i console.log how the #form values will be sent?

i know we can manally log any input value by its selector

console.log('inputName='+$('#inputId').val()+'....)

But is there -simpler- a way to log all input values? if it's posible to do it when any input changes

like image 985
Toni Michel Caubet Avatar asked Dec 16 '11 09:12

Toni Michel Caubet


People also ask

How do I console log?

Steps to Open the Console Log in Google Chrome By default, the Inspect will open the "Elements" tab in the Developer Tools. Click on the "Console" tab which is to the right of "Elements". Now you can see the Console and any output that has been written to the Console log.

How do I check the value of console log?

log(), then the function will display the value of the passed function(). Output: Passing a number with message as an argument: If the number is passed to the function console. log(), then the function will display it along with the given message.

How do I use the console to log into a different line?

To display a console. log in multiple lines we need to break the line with \n console. log("Hello \n world!"); That will display it like this: Hello world!

How do I return a value from console log?

console. log() is a function used to print information to the console. return on the other hand is a call to pass some value back up to where the call was made. For instance, let's say you create a function called square() that takes in a single numeric parameter and returns that value squared.


2 Answers

You can use serialize to serialize the form elements to a string for logging. It follows the same rules for including or not including elements as normal form submission. The only caveat is that the content of input type="file" fields isn't serialized, for perhaps obvious reasons.

To fire it when any of the inputs changes:

$("form :input").change(function() {
    console.log($(this).closest('form').serialize());
});

Live demo using the form shown in the documentation

like image 66
T.J. Crowder Avatar answered Sep 23 '22 07:09

T.J. Crowder


You may get in form of query string using $("form").serialize().

like image 31
Abdul Munim Avatar answered Sep 21 '22 07:09

Abdul Munim