简体   繁体   中英

How to post all data of form to php all together using javascript

I have an HTML form

<form>

Name <input name=nm type=text">
Password <input name=pass type=password >

I want to send the value of both the field, how to do this using js

You can do it using serialize()

<!DOCTYPE html>
<html>
<head>
<script src="https://ajax.googleapis.com/ajax/libs/jquery/3.5.1/jquery.min.js"></script>
<script>
$(document).ready(function(){
  $("button").click(function(){
    $("div").text($("form").serialize());
  });
});
</script>
</head>
<body>

<form action="">
  First name: <input type="text" name="FirstName" value="Mickey"><br>
  Password: <input type="text" name="LastName" value="Mouse"><br>
</form>

<button>Serialize form values</button>
body>

<form action="">
  First name: <input type="text" name="nm" value="Mickey"><br>
  Last name: <input type="password" name="password" value="Mouse"><br>
</form>

<button>Serialize form values</button>

<div></div>
</body>
</html>
<div></div>

</body>
</html>

Hope this will help you

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM