Last active
July 10, 2021 04:07
-
-
Save madcoderBubt/0ab09a0a3d1e028f58be3dbc00b55ddc to your computer and use it in GitHub Desktop.
form data to json data conversion
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| <!DOCTYPE html> | |
| <html lang="en"> | |
| <head> | |
| <meta charset="UTF-8"> | |
| <meta http-equiv="X-UA-Compatible" content="IE=edge"> | |
| <meta name="viewport" content="width=device-width, initial-scale=1.0"> | |
| <title>Document</title> | |
| </head> | |
| <body> | |
| <div class=""> | |
| <form action="#" method="post" id="formData"> | |
| <input type="text" name="data_1" id="data_1" placeholder="1"><br> | |
| <input type="text" name="data_2" id="data_2" placeholder="2"><br> | |
| <input type="button" onclick="formToJson()" value="Boom Yeah"> | |
| </form> | |
| </div> | |
| <script src="https://code.jquery.com/jquery-3.6.0.js"></script> | |
| <script type="text/javascript"> | |
| let formToJson = function(){ | |
| let form = new FormData($("form#formData")[0]); | |
| for (let [key, value] of form) { | |
| console.log(key + ": "+ value); | |
| } | |
| console.log(form); | |
| let jsonData = Object.fromEntries(form.entries()); | |
| console.log(jsonData); | |
| } | |
| </script> | |
| </body> | |
| </html> |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment