Set the value of the input field - Javascript jQuery Method and Property

Javascript examples for jQuery Method and Property:val

Description

Set the value of the input field

Demo Code

ResultView the demo in separate window

<!DOCTYPE html>
<html>
<head>
<script src="https://ajax.googleapis.com/ajax/libs/jquery/3.2.1/jquery.min.js"></script>
<script>
$(document).ready(function(){
    $("button").click(function(){
        $("input:text").val(function(n, c){
            return c + " test";
        });/*from w w  w . j  av a2  s . c  o m*/
    });
});
</script>
</head>
<body>

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

<button>test</button>

</body>
</html>

Related Tutorials