最新消息:雨落星辰是一个专注网站SEO优化、网站SEO诊断、搜索引擎研究、网络营销推广、网站策划运营及站长类的自媒体原创博客

javascript - Show form data in console on submit - Stack Overflow

programmeradmin5浏览0评论

Is it possible to show all the form data in console when the form is submitted and then the data is posted to the server as well?

Something like that?

<form action="" method="POST" onSubmit="console.log(All Form Data)">

Thanks Ahmar.

Is it possible to show all the form data in console when the form is submitted and then the data is posted to the server as well?

Something like that?

<form action="http://whatever." method="POST" onSubmit="console.log(All Form Data)">

Thanks Ahmar.

Share Improve this question asked Apr 13, 2014 at 15:05 Ahmar AliAhmar Ali 1,0788 gold badges28 silver badges53 bronze badges 3
  • Yes, it's possible. What have you tried? – Teemu Commented Apr 13, 2014 at 15:06
  • write a function that would print all the form data in console, and call it from "onSubmit" in form tag. – vivek_nk Commented Apr 13, 2014 at 15:10
  • It is possible using JavaScript or jQuery, but you should be careful what kind of data it is - posting passwords to the console is a massive security risk and if you're dealing with more sensitive stuff like bank details then posting the data to the console could get you prosecuted. – ArtOfCode Commented Apr 13, 2014 at 15:10
Add a ment  | 

1 Answer 1

Reset to default 2

Try

$(function() {
  $('form').submit(function() {
    console.log('Input 1: '+$('input[name="input1"]').val() + ' Input 2: '+ $('input[name="input2"]').val()); // etc.
  });
});

or give Id's to inputs then

<form onSubmit="console.log('Input 1: '+document.getElementById('input1').value + ' Input 2: '+document.getElementById('input2').value)">
发布评论

评论列表(0)

  1. 暂无评论