Codepedia
.info
Home
About
Demos
Tools
SVG Wave Generator
Colors
Edit This Code :
<html> <head> </head> <body> <script src="https://ajax.googleapis.com/ajax/libs/jquery/1.11.2/jquery.min.js"></script><br/> <input id="txtName" value="" type="text"/> <input id="myInputHidden" name="myInputName" type="hidden" value="Codepedia" /> <button id="btnShow1"> Set Hidden field Value by ID</button> <button id="btnShow2"> Set Hidden field Value by Name</button> <br/> <script> $(document).ready(function(){ $("#btnShow1").on('click', function () { var getTxtValue = $("#txtName").val(); // this gives textbox value $("#myInputHidden").val(getTxtValue); // this will set hidden field value alert(getTxtValue); }); $("#btnShow2").on('click', function () { var getTxtValue = $("#txtName").val(); // this gives textbox value $("input[name=myInputName]").val(getTxtValue); // this will set hidden field value alert(getTxtValue); }); }); </script> </body> </html>
➤ Run / View
Result :