JQuery-Input-val

by powenko

HTML

<!DOCTYPE html>
<html>
<head>
<script src="https://ajax.googleapis.com/ajax/libs/jquery/3.5.1/jquery.min.js"></script>
</head>
<body>

<p>Name: <input type="text" name="user"></p>

<button id="div1">Set the value of the input field</button>
<button id="div2">get the value of the input field</button>

</body>
</html>

JavaScript

$(document).ready(function(){
  $("button#div1").click(function(){
    $("input:text").val("powenko");
  });
  $("button#div2").click(function(){
    t1=$("input:text").val();
    alert(t1);
  });
});