Try It Editor
Tip: Press
Ctrl/⌘ + Enter
to Run
▶ Run
Reset
Copy
Download
Code
<!DOCTYPE html> <html> <head> <meta charset="UTF-8"> <title>Read & Set Values</title> <script src="https://code.jquery.com/jquery-3.6.0.min.js"></script> </head> <body> <form id="f"> <input id="name" name="name" placeholder="Name"> <label><input type="checkbox" id="agree" name="agree"> Agree</label> <select id="role" name="role"><option>User</option><option>Admin</option></select> </form> <button id="get">Get Values</button> <button id="set">Set Values</button> <pre id="out"></pre> <script> $("#get").click(function(){ $("#out").text( "name=" + $("#name").val() + "\n" + "agree=" + $("#agree").prop("checked") + "\n" + "role=" + $("#role").val() ); }); $("#set").click(function(){ $("#name").val("Sonu"); $("#agree").prop("checked", true); $("#role").val("Admin"); }); </script> </body> </html>
Output